“Control”类型的值无法转换为“CheckBox”

时间:2015-10-03 16:52:17

标签: asp.net .net

我试图在网格视图中遍历每一行,但是当我创建我的循环时,我收到错误

gridview的aspx代码

<asp:GridView ID="gvContactList" runat="server" CssClass="table table-bordered table-striped table-hover table blue">
     <Columns>
           <asp:CheckBoxField />
     </Columns>
</asp:GridView>

使用代码

   For Each row As GridViewRow In gvContactList.Rows
        Dim Row As GridViewRow = gvContactList.SelectedRow
        Dim chk As CheckBox = TryCast(Row.Cells(0).Controls(0), CheckBox)

        Dim SelectedEmail As String
        If String.IsNullOrEmpty(Row.Cells(4).Text) Or Row.Cells(4).Text.Trim() = "&nbsp;" Then
            SelectedEmail = Row.Cells(2).Text
        Else
            SelectedEmail = Row.Cells(4).Text
        End If

        txtEmailTo.Text = txtEmailTo.Text & SelectedEmail & "; "

    Next

违规行是这个,但不知道如何解决它

Dim chk As CheckBox = TryCast(Row.Cells(0).Controls(0), CheckBox)

给出错误

  

'Control'类型的值无法转换为'CheckBox'

0 个答案:

没有答案