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

前端 未结 12 1668
陌清茗
陌清茗 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 08:59

    As said by others, RowDataBound or RowCreated event should work but if you want to avoid events declaration and put the whole code just below DataBind function call, you can do the following:

    GridView1.DataBind()
    If GridView1.Rows.Count > 0 Then
        GridView1.HeaderRow.Cells(0).Visible = False
        For i As Integer = 0 To GridView1.Rows.Count - 1
            GridView1.Rows(i).Cells(0).Visible = False
        Next
    End If
    

提交回复
热议问题