Tech Off Thread

4 posts

string.empty and  

Back to Forum: Tech Off
  • Raghavendra_​Mudugal

    Binding dataset to the datagrid... which contains 6 columns and 1 column has string.empty value

    when I see that row.col.value, it contains " " in it. If I hold this value in the string variable, say str1, then str1 = " ". But in the database that field had zero length string, that is string.empty(and database is mssql2k) even, i checked the length of that field using the SQL query, it gives 0 (zero), then why this datagrid is interpreting that string.empty = " ". So finally to solve this I have to replace that " " with "". But still I don't get it... is this a normal way or am I missing something.

  • LostIn​Tangent

    The DataGrid/GridView actually looks for empty cells and fills them with a   for you.

  • Jorgie

    There are many things you have to remember about asp web controls. Two of them are:

    1. When your code runs on the server side, it is seeing the ASP control, not the HTML control that ends up on the page.

    2. ASP controls do not map in a one to one fashion to HTML controls. ASP has to build them out of one or more HTML controls and manipulate their contents to fit the control.

    In this case, #1 means that you are looking at an abstraction that will later be rendered into HTML. #2 means that when a asp:DataGrid is turned into an HTML TABLE, empty cells cannot be left empty or they will not be displayed properly. To deal with this, they are 'filled' with a non-breaking-space.

    Jorgie

  • stevo_

      is the non breaking space character in html... or.. a space. Most elements that don't contain a value have the ability to collapse theirself (disapear). Putting a space in ensures they don't.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.