?
Solved

how to set the gridview to display only populated row

Posted on 2012-04-11
5
Medium Priority
?
171 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 1500 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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 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