我有一个GridView
,我在RunTime上用DataTable
填充,但我想隐藏其中一个列已经加载到GridView
中,我试过了:
Me.GridView1.Columns(0).Visible = False
但它给了我超出范围的例外。
你知道其他任何方法吗?
答案 0 :(得分:0)
试试这个:
Private Sub GridView1_DataBound(sender As Object, e As EventArgs) Handles GridView1.DataBound
GridView1.Columns(0).Visible = False
End Sub
答案 1 :(得分:0)
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[index].Visible = false;
}
答案 2 :(得分:0)
感谢大家的帮助,我尝试了grid.ros.cells(i).visible = false但是它没有用但读取我发现我必须隐藏标题行,所以我让这个函数隐藏任何行在任何网格中
Private Sub HideColumn(ByRef grid As GridView, ByVal x As Integer)
If grid.Rows.Count > 0 Then
grid.HeaderRow().Cells(x).Visible = False
For i As Integer = 0 To grid.Rows.Count - 1
grid.Rows(i).Cells(x).Visible = False
Next
End If
End Sub