Solved

how to set the gridview to display only populated row

Posted on 2012-04-11
5
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

690 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