Skip to content
Loading
How to hide column which have null values in gridview.
  • Subin Thomas
    ohh is it amit okay i will paste it in vs
    +1
  • Subin Thomas
    my gridview name is ActiveGridView5 mohsin
    +1
  • Amit Kumar
    Sorry Dost, I m replying with mobile then so I can't do that , you can do one thing paste this code in Visual Studio then you can understand easily.
    +2
  • Mohsin Arif
    hi please tell me your gridview name or send me snapshot of your code 
    +2
  • Subin Thomas
    hey amit can you put the code in syntax highliter code so that i can understand lil easy
    +1
  • Subin Thomas
    its not working mohsin i tried the code you suggested
    +1
  • Amit Kumar
    Hi,
    Use the below code . It will help you.
    1. protected void dataGrid_DataBinding(object sender, EventArgs e)  
    2. {  
    3. int i = dataGrid.Items.Count;int j = 0;  
    4. foreach (DataGridItem item in dataGrid.Items)  
    5. {  
    6. string id = (item.Cells[2].FindControl("lblTableId"as Label).Text;  
    7.    
    8. if (string.IsNullOrEmpty(id))  
    9. {j++;}}if (j == i)dataGrid.Columns[2].Visible = false;}  
    +2
  • Subin Thomas
    im getting exception on gvSearchEngine its saying the name does not exist in current context
    +1
  • Mohsin Arif
    hi
    try this one
    1. protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)  
    2.     {  
    3.         if (e.Row.RowType == DataControlRowType.DataRow)  
    4.             {  
    5.                string val = e.Row.Cells[0].ToString();  //check first cell value  
    6.                if(string.IsNullorEmpty(val) )               
    7.                 {  
    8.                 gvSearchEngine.Columns[0].Visible = false;     //Hides First Column  
    9.                 }  
    10.   
    11.             }  
    12.     }  
     
    +2