vb.net - Gridview 显示和隐藏特定列

我有一个 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

最佳答案

如果您已将 AutoGenerateColumns 设置为 True,则 Column-Count 将为 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

https://stackoverflow.com/questions/8755773/

相关文章:

assembly - 'label' 关键字在 MASM 中如何工作?

matplotlib - 如何更改 matplotlib 3D 图轴的颜色?

tsql - 返回 T-SQL 中两个日期之间的月/年

objective-c - 在 objective-c 中获取颜色分量

objective-c - Ada 支持 put_line 中的变量吗?

python-2.7 - Python None 如果检查失败

r - 描述性表格 - 如何创建包含数值变量和分类变量的表格

perl - 如何测试是否在 Perl 正则表达式匹配中定义了捕获?

php - Wordpress 检查是否是标签页

google-maps - 谷歌地图标记仅在 iPhone/iPad 上在特定缩放级别消失