hide a column

HLRosenberger
HLRosenberger used Ask the Experts™
on
How do I completely hide a column in the GridView?   I have a datatable which is bound to the Grid, and I auto generated the columns.  But everything I try - setting the width to 0, make the column invisible - I still see the column.    Making the column invisible merely hides the data,  but the column is still there.

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Have you tried it in RowCreated event of grid view ??


 

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false;
}

Open in new window

Set the column's css in rowdatabound event and in css place the hide code:
ASPX code
protected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].CssClass = "hiddenColumn";
         }

        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].CssClass = "hiddenColumn";
        }

}

CSS code
.hiddenColumn
{
    display:none;
}
Top Expert 2009

Commented:
You can also try:

myDataGrid.Columns[0].Visible = false;

Arun

Author

Commented:
That's the ticket!  Making is invisible in the RowCreated event!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial