Thursday, February 3, 2011

How to show/hide column in GridView by different ways

How to show/hide column in GridView

1. To hide a column just set the width to 0. To show it again set the width to auto.
Code:

GridView1.Columns[0].ItemStyle.Width = 0;


2. Hide the column
Code:
        GridView1.Columns[6].Visible = false;


3. Different way to Hide the columns
Code:

protected void Gridview1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Index of column to be hide
e.Row.Cells[0].Visible = false;

}
if (e.Row.RowType == DataControlRowType.Header)
{
// Index of column to be hide
e.Row.Cells[0].Visible = false;
}
}

No comments:

Post a Comment