我的项目中有一个数据网格,其中一个复选框作为模板字段;但我无法访问该checkbox.checked
属性。有人有什么主意吗?
我的 ASP 代码:
<asp:GridView ID="GVP" runat="server" AutoGenerateColumns="False" DataSourceID="DSP">
<Columns>
<asp:TemplateField HeaderStyle-Width="5%" ItemStyle-Width="5%" FooterStyle-Width ="5%">
<ItemTemplate>
<asp:CheckBox ID="SelectCb" runat="server"></asp:CheckBox>
</ItemTemplate>
<FooterStyle Width="5%"/>
<HeaderStyle Width="5%"/>
<ItemStyle Width="5%"/>
</asp:TemplateField>
<asp:BoundField DataField="Answers" HeaderText="Options" SortExpression="Answers" />
</Columns>
</asp:GridView>
我背后的VB代码:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonNext.Click
Dim SelectedBox As Boolean = False
For Each row As GridViewRow In GVP.Rows
Dim cb As CheckBox = row.FindControl("SelectCb")
If cb IsNot Nothing AndAlso cb.Checked Then
SelectedBox = True
Dim RID As Integer = Convert.ToInt32(GVP.DataKeys(row.RowIndex).Value)
Else
ShowMessage("You did not select anything")
End if