将可编辑的CheckBoxField添加到gridview

时间:2013-03-18 13:13:19

标签: asp.net vb.net gridview user-controls

我正在尝试以编程方式将复选框列添加到网格视图中。此网格视图有多个其他列,但我只希望复选框列可编辑。我见过的唯一例子要求我为每一行添加一个“编辑”链接。我希望默认情况下复选框列可以编辑,而不需要链接。该复选框还应支持autopost后备。有人有什么建议吗?以下是我到目前为止:

    Dim gv As New GridView

    With gv
        .ID = "gridViewFoundUsers"
        .AutoGenerateColumns = False
        .DataKeyNames = New String() {"UserId"}
        .GridLines = GridLines.Both
        .AllowSorting = True
        .AllowPaging = True
        .PageSize = numRows
        .Width = tableWidth
        .BorderColor = Drawing.ColorTranslator.FromHtml("#808080")
        .AutoGenerateEditButton = True

        .HeaderStyle.CssClass = foundUserHeadStyle
        .RowStyle.CssClass = foundUserEvenRows
        .Columns.Clear()

        Dim UserIdTF As New BoundField
        With UserIdTF
            .DataField = "UserId"
            .HeaderText = "UserID"
            .SortExpression = "UserId"
            .ItemStyle.Wrap = True
            .ItemStyle.Width = 100
        End With

        Dim DomainTF As New BoundField
        With DomainTF
            .HeaderText = "Domain"
            .DataField = "Domain"
            .SortExpression = "Domain"
            .ItemStyle.Wrap = False
            .HeaderStyle.Font.Underline = False
        End With

        Dim SelectUserTF As New CheckBoxField
        With SelectUserTF
            .HeaderText = "Select User"
            .ItemStyle.Wrap = False
            .DataField = "isSelected"
        End With

        .Columns.Add(UserIdTF)
        .Columns.Add(DomainTF)            
        .Columns.Add(SelectUserTF)
     End With

gridview是复合服务器控件的一部分,因此没有客户端代码页。

谢谢!

0 个答案:

没有答案