Link to home
Start Free TrialLog in
Avatar of Meinhoonaa
Meinhoonaa

asked on

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
Avatar of BuggyCoder
BuggyCoder
Flag of India image

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;
Avatar of Meinhoonaa
Meinhoonaa

ASKER

i need to do it at the grid level
ASKER CERTIFIED SOLUTION
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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;  

}
I need to remove the row in the grid. Making the row invisible is keeping extra rows in the grid.