hide column in datagrid
thanks,
Supriya
Hi,
Use the, DataViewColumn.Visible property:
dataGridView1.Columns["Col2"].Visible = false;
cheers,
Paul June A. Domag
-mark
Program Manager
Microsoft
This post is provided "as-is"
how to make sure only the columns for the ItemTemplate specified should be displayed in a normal mode and in edit mode more columns should be displayed.
<asp:TemplateField ..>
<ItemTemplate>
...
</ItemTemplate>
<EditItemTemplate>
...
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField ..>
<EditItemTemplate>
...
</EditItemTemplate>
</asp:TemplateField>
Both columns will be displayed in both normal and in edit node, even if we don’t specify an ItemTemplate for the other TemplateField. In some cases you probably want to display few columns in normal mode, and some more columns in edit mode. By using the RowDataBound event of the GridView, we can programmatically hide columns. So if we have a GridView with 4 columns (including the edit buttons etc) and want to hide the last two columns, we can do something like this in the RowDataBound event:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (GridView1.EditIndex > 0)
return;
if ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) &&
(e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header))
{
e.Row.Cells[2].Visible = false;
e.Row.Cells[3].Visible = false;
}
}