Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How determine if gridview column has no data?

Posted on 2010-09-20
3
Medium Priority
?
732 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
[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
3 Comments
 
LVL 42

Accepted Solution

by:
sedgwick 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 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