Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
2.30/5 (3 votes)
See more:
For a specific item in database returning some set of values and I am binding in gridview.
For null value, gridview cell is showing empty. How to write "not available" in the empty cells in gridview?
Updated 23-Mar-21 18:26pm
Sergey Alexandrovich Kryukov 1-Nov-13 1:29am    
What exactly do you mean be "gridview"? Full type name, please. When it comes to UI, you should always tag the UI library/framework or application type you are trying to use.

1 solution

I assume this is ASP.NET. Try this:
protected void Your_GridView_RowDataBound(object sender, GridViewRowEventArgs e)
   if (e.Row.RowType == DataControlRowType.DataRow)
         for (int i = 0; i < e.Row.Cells.Count; i++)
           if (e.Row.Cells[i].Text == "&nbsp;")
                e.Row.Cells[i].Text = "not available";

Share this answer
Shibasankar 1-Nov-13 1:44am    
Sir, It's working for only textboxes inside gridview. But I am trying to check boundfield value.
when I am retrieving the value of the empty cell, it is showing only a space, but when I am checking the length of string of thet cell it's giving 6.
Thanks7872 1-Nov-13 2:00am    
First of all,the code i provided doesn't point at any textbox or any control. Check the value that you are binding to that GridView. If its showing length of 6,it means that its not empty. You stated in your question that for null value its showing empty. In that case,above code works.
Shibasankar 1-Nov-13 2:06am    
yes, in my database table the value is showing null. But when I am binding with gridview and checking null value for cell, i am not getting output.
In message alert box, the empty cell is showing blank, but when m getting the length it is showing 6.
Thanks7872 1-Nov-13 2:38am    
Try the updated code.
Shibasankar 1-Nov-13 2:59am    
Thank You Very much. Now it's working...

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