BC30456:'已选中'不是'复选框'

时间:2017-07-06 16:22:13

标签: vb.net

我有一个带有checkBox TemplateField的gridView控件。我试图根据选中的复选框控件从gridvie中删除记录,但不断收到错误

  

BC30456:'已选中'不是'复选框'的成员。

下面是我的button_click子程序,应该执行删除操作。

Protected Sub DeleteSelectedProducts_Click(sender As Object, e As EventArgs) Handles DeleteSelectedProducts.Click
    Try
        Dim atLeastOneRowDeleted As Boolean = False

        For Each row As GridViewRow In GridView1.Rows

            Dim cb As CheckBox = row.FindControl("ProductSelector")
            If cb IsNot Nothing AndAlso cb.Checked Then

                atLeastOneRowDeleted = True

                Dim productID As Integer = _
                    Convert.ToInt32(GridView1.DataKeys(row.RowIndex).Value)

                DeleteResults.Text &= String.Format( _
                    "This would have deleted ProductID {0}<br />", productID)

            End If
        Next
        DeleteResults.Visible = atLeastOneRowDeleted
    Catch ex As Exception

    End Try

End Sub

1 个答案:

答案 0 :(得分:1)

我猜这是WPF,因为WinForms CheckBoxASP.NET CheckBox都有Checked属性。

对于WPF,您必须使用CheckBox.IsChecked

If cb IsNot Nothing AndAlso cb.IsChecked Then