Solved

How determine if gridview column has no data?

Posted on 2010-09-20
3
730 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 125 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 125 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 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