我有一个gridview,其中有一个特定的列Date
。我已将列的Visible
属性设置为false,因为我想在不同的页面条件下显示。请告诉我如何使用vb.net我的Date
列应该在运行时显示或隐藏
更新
我目前的代码是
If Not Page.User.Identity.Name = "bilal" Then
GridView1.AutoGenerateEditButton = False
GridView2.AutoGenerateEditButton = False
GridView3.AutoGenerateEditButton = False
Else
GridView1.AutoGenerateEditButton = True
GridView1.AutoGenerateColumns = True
GridView1.DataBind()
If GridView1.Columns.Count > 0 Then
'assuming your date-column is the first '
GridView1.Columns(3).Visible = True
Else
GridView1.HeaderRow.Cells(0).Visible = False
For Each gvr As GridViewRow In GridView1.Rows
gvr.Cells(0).Visible = True
Next
End If
GridView2.AutoGenerateEditButton = True
GridView3.AutoGenerateEditButton = True
End If
答案 0 :(得分:8)
如果您将AutoGenerateColumns
设置为True
,则列数将为0,然后您需要循环行并显示/隐藏相应的单元格。否则,您可以使用Visible
属性。
GridView1.DataBind()
If GridView1.Columns.Count > 0 Then
'assuming your date-column is the 4.'
GridView1.Columns(3).Visible = True
Else
GridView1.HeaderRow.Cells(3).Visible = False
For Each gvr As GridViewRow In GridView1.Rows
gvr.Cells(3).Visible = True
Next
End If