Solved

How determine if gridview column has no data?

Posted on 2010-09-20
3
716 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:
sedgwick earned 125 total points
Comment Utility
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 125 total points
Comment Utility
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
Comment Utility
will take a look later
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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

16 Experts available now in Live!

Get 1:1 Help Now