Solved

how to set the gridview to display only populated row

Posted on 2012-04-11
5
165 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:Meinhoonaa
  • 2
  • 2
5 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37835014
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
 

Author Comment

by:Meinhoonaa
ID: 37835048
i need to do it at the grid level
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37835063
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
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 37835481
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
 

Author Comment

by:Meinhoonaa
ID: 37835802
I need to remove the row in the grid. Making the row invisible is keeping extra rows in the grid.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to dynamically set the form action using jQuery.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now