Question

I have a GridView connected to my database through an sql data source. It is bound by the follow code:

    firstview = "SELECT ID, DC, DD, CYM, CB, ST FROM SCH_SCHEMANAME.TABLENAME WHERE CI = " & txtboxvalue.text & " AND ST = 'whatever' AND D = 0"
  SqlDataSource1.SelectCommand = firstview
        GridView1.DataBind()

There is no problem connecting to the database. Inside the database, one of the column contains extra whitespace. To make a long story short, the DD column is a short sentence that contains more than one space between some words. e.g. "This_is____a_sentence_stored___in_the_____dd_column" where each underscore is a space in this example.

When I do the databind, the spaces in between the words are all reduced to 1 space. I do, however, need to keep the exact amount of spaces between each word when the data is bound in the GridView. At the moment, it is showing in the GridView as "This_is_a_sentence_stored_in_the_dd_column" but I want to keep the amount of spaces rather than have them automatically cut down.

Can anyone help?

Was it helpful?

Solution

I was able to fix by doing the following on the RowDataBound event for the gridview.

e.Row.Cells(4).Text = e.Row.Cells(4).Text.Replace(" ", " ")

The database was retrieving the correct value, but the spaces were being parsed/encoded. JPW's links helped me with the line of code.

Thanks

OTHER TIPS

It is not about a database. The browser treats multiple spaces as one. E.g. see several workarounds here: http://www.codeproject.com/Articles/30740/Avoid-Multiple-Space-Elimination-in-ASP-NET-GridVi

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top