how to set the gridview to display only populated row

I have added logic to not to show the row. But the grid is showing empty rows. My code shown below:

                e.Row.Visible = False
MeinhoonaaAsked:
Who is Participating?
 
BuggyCoderConnect With a Mentor Commented:
you have to remove the row using removeat(index) method of gridview, see the discussion here:-

http://www.codeproject.com/Questions/147046/deleting-empty-row-of-datagridview
0
 
BuggyCoderCommented:
why not bind only those rows which have data.
here is linq to help you select rows which have data:-

from row in table.AsEnumerable()
where table.Columns.Cast<DataColumn>.Any(col => !row.IsNull(col))
select row;
0
 
MeinhoonaaAuthor Commented:
i need to do it at the grid level
0
 
PagodNaUtakCommented:
Put your code in the RowDataBound Control as shown below:

private void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)  {    
           // Check if the first cell is empty, if it is empty then hide it.
           // Note: You can change the if statement based on your needs.
           if (e.Row.Cells[0].Text == "")          
                    e.Row.Visible = false;  

}
0
 
MeinhoonaaAuthor Commented:
I need to remove the row in the grid. Making the row invisible is keeping extra rows in the grid.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.