Click here to Skip to main content
15,916,949 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

I have a gridview, when I get the selecteditem.cells for a column, if the database column is Null or Empty, and I assign that to my web form text control, the control reads " " instead of a string.empty. How can i solve this .
Posted
Comments
[no name] 30-Aug-13 9:30am    
How can you solve what? Have you considered assigning an empty string to your text control instead of " "?

You could try this...

Let say your gridview is called gvUsers in the RowDataBound method you could try this...

C#
protected void gvUsers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.DataRow) return;

        DataRow CurrentRow = ((DataRow)sender);
        for (int i = 0; i < CurrentRow.ItemArray.Count(); i++)
            if (CurrentRow.ItemArray[i].ToString() == " ")
                CurrentRow.ItemArray[i] = string.Empty;
    }
 
Share this answer
 
You can assign an empty string or some default text in case your column in the database table is having an empty string or null value.
 
Share this answer
 
Comments
Ostwal Aarti 31-Aug-13 3:38am    
thank you for reply . But i already set the default value as '' in database .
Secondly if i apply space then it will increase the size of database.As whole project consist of n number of fields. I search same issue on Google i found one solution , set html encode=false, convert empty field as null but it is not working. so can please suggest me answer so i can change through out the project

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900