How to hide columns in an ASP.NET GridView with auto-generated columns?

前端 未结 12 1683
陌清茗
陌清茗 2020-11-30 08:28

GridView1.Columns.Count is always zero even SqlDataSource1.DataBind();

But Grid is ok

I can do

for (int i = 0; i < GridView1.HeaderRow.Cel         


        
12条回答
  •  清歌不尽
    2020-11-30 09:11

    Try putting the e.Row.Cells[0].Visible = false; inside the RowCreated event of your grid.

    protected void bla_RowCreated(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Visible = false; // hides the first column
    }
    

    This way it auto-hides the whole column.

    You don't have access to the generated columns through grid.Columns[i] in your gridview's DataBound event.

提交回复
热议问题