Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have gridview with 12 column and one of the column have 3 value "ex1" "ex2" "ex3"
i want if ex1 apppear hide some columns , if ex2 appear hide others columns and so on

i try using row roundabout but dint work nothing is hiding

What I have tried:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          Label lbl = e.Row.FindControl("Label1") as Label;
          for (int i = 0; i < GridView1.Columns.Count; i++)
          {
              if (lbl.Text == "Client")
              {
                  GridView1.Columns[13].Visible = false;
              }
          }



      }
  }
Posted
Updated 23-May-17 7:25am
v2
Comments
Ehsan Sajjad 23-May-17 11:43am    
so what happens when you run the above code?
Learn.net37 23-May-17 12:30pm    
nothing happens the column still appear

1 solution

if (e.Row.RowType == DataControlRowType.DataRow)
{
int index = GetColumnIndexByName(e.Row, "myDataField");

GridView1.Columns[index].Visible = false;
}
 
Share this answer
 
Comments
Learn.net37 23-May-17 14:02pm    
thank u can u explain what is int index = GetColumnIndexByName(e.Row, "myDataField");
line do i mean GetColumnIndexByName ( column name )? and (mydatafield) name of the label ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900