Data that contains extra spaces
-
Hi Mayl :) Did you want the datagrid to discard the extra spaces, so no matter how many spaces there are, then it should only display one space...? Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't
-
mayl wrote:
I'm trying to populate a datagrid with records that contains spaces. Ex: I have a record that has a value of "Contain Three spaces". However, when it binds, it shows up as "Contain Three spaces". Any ideas?
Um... if the field contains "Contain Three spaces", and it's displaying in your DataGrid as "Contain Three spaces", what exactly is the problem?
-
I get it now :) It's standard behavior in a browser to compress your three spaces as one (which is what it has done in your posts, too). My guess is that if you view the resulting page source in your browser, the values have been outputted with the three spaces. To ensure literal spaces, you can use the entity
(non-breaking space). You might want to use a custom function in your grid column's ItemTemplate that would replace a " " character with " ". -
Hi I'm trying to populate a datagrid with records that contains spaces. Ex: I have a record that has a value of "Contain Three spaces". However, when it binds, it shows up as "Contain Three spaces". Any ideas? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here grddatabind() End Sub Sub grddatabind() Dim strConn As String = ConfigurationSettings.AppSettings("CONN_STR") Dim objOraConn As New OracleConnection(strConn) Dim objDV As DataView Dim objDS As New DataSet Dim objOraCmd As OracleCommand Dim objOraAdapter As OracleDataAdapter Dim sqlStr As String sqlStr = "select * from table" Try objOraCmd = New OracleCommand(sqlStr, objOraConn) objOraAdapter = New OracleDataAdapter(objOraCmd) objOraConn.Open() objOraAdapter.Fill(objDS) objDV = New DataView(objDS.Tables(0)) Me.DataGrid1.DataSource = objDV Me.DataGrid1.DataBind() Catch ex As Exception Finally If objOraConn.State = ConnectionState.Open Then objOraConn.Close() End If End Try End Sub thank you
If you want the DataGrid to display all the spaces, then subscribe to the DataGrid's
ItemDataBound
event, and add code like this:private void dgSampleSort_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Cells[0].Text = e.Item.Cells[0].Text.Replace(Environment.NewLine, " ");
}Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't
-
I get it now :) It's standard behavior in a browser to compress your three spaces as one (which is what it has done in your posts, too). My guess is that if you view the resulting page source in your browser, the values have been outputted with the three spaces. To ensure literal spaces, you can use the entity
(non-breaking space). You might want to use a custom function in your grid column's ItemTemplate that would replace a " " character with " ". -
If you want the DataGrid to display all the spaces, then subscribe to the DataGrid's
ItemDataBound
event, and add code like this:private void dgSampleSort_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Cells[0].Text = e.Item.Cells[0].Text.Replace(Environment.NewLine, " ");
}Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't
-
Hi Mike I had modified my sql statement - select replace(filename, ' ',' ') from table It displays the extra spaces correctly, however, my datagrid does not wrap (I have ItemStyle-Wrap="True"). Any ideas? thank you
Hmmm... yea, it wouldn't wrap because is a non-breaking space... Well, one more thing you could try is to use your spaces as they are (no replacement for 's) and surround the value in a
<span style="white-space: pre;">
tag orstyle="white-space: pre-wrap"
. I'm not sure what the browser support for thewhite-space
style attribute is though. -
Hi Mike I had modified my sql statement - select replace(filename, ' ',' ') from table It displays the extra spaces correctly, however, my datagrid does not wrap (I have ItemStyle-Wrap="True"). Any ideas? thank you
-
Hi I added it but it didn't work. so I changed my sql statement (select replace(file_name, ' ',' ') from table) and it worked. However, the datagrid does not wrapped even though I have ItemStyle-Wrap="True". Any ideas? thank you
Do you have fixed width on the columns? That may help to force a linebreak. Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't
-
Do you have fixed width on the columns? That may help to force a linebreak. Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't