Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How determine if gridview column has no data?

Posted on 2010-09-20
3
Medium Priority
?
741 Views
Last Modified: 2013-12-16
I have a gridview that I bind with code. How can I determine if a gridview column has no data? I want to hide that column if it doesn't have data.
0
Comment
Question by:RobertNZana
3 Comments
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 500 total points
ID: 33723188
you can simply iterate throw all rows in the datagrid and check if the cell in requested column is empty.
something like:
            DataGridView dgv = new DataGridView();
            int count = dgv.Rows.Cast<DataGridViewRow>().Where(n => n.Cells[columnName].Value != null && !string.IsNullOrEmpty(n.Cells[columnName].Value.ToString())).Count();
            if (count == 0)
            {
                //column is empty and has no data
            }
0
 
LVL 22

Assisted Solution

by:Mrunal
Mrunal earned 500 total points
ID: 33723790
you can also do like this:

protected void MyGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.Header)
 {
  //check here for black or null data. If found...then execute...
  e.Row.Cells[index].Visible = false;
 }
 if(e.Row.RowType == DataControlRowType.DataRow)
 {
  //check here for black or null data. If found...then execute...
  e.Row.Cells[index].Visible = false;
 }
}
0
 
LVL 9

Author Closing Comment

by:RobertNZana
ID: 33756200
will take a look later
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

971 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