************************************************************************
* 急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急 *
************************************************************************
MyDataGrid控件中,我运用了以下CheckBox模板:
<asp:TemplateColumn HeaderText="Delete">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:CheckBox Runat="server" ID="chkDelete"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:CheckBox Runat="server" ID="chkDelete"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
在vb.net里面,我写了以下程序:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Int32
Dim cb As CheckBox
Dim n As Int32 = MyDataGrid.Items.Count - 1
For i = 0 To n
cb = CType(MyDataGrid.Items(i).Cells(1).FindControl("chkDelete"), CheckBox)
If cb.Checked = True Then
Response.Write(MyDataGrid.Items(i).Cells(0).Text)
Else
Response.Write("No")
End If
Response.Write("<br>")
Next
Dim i As Int32
Dim cb As CheckBox
Dim n As Int32 = MyDataGrid.Items.Count - 1
For i = 0 To n
cb = CType(MyDataGrid.Items(i).Cells(1).FindControl("chkDelete"), CheckBox)
If cb.Checked = True Then
Response.Write(MyDataGrid.Items(i).Cells(0).Text)
Else
Response.Write("No")
End If
Response.Write("<br>")
Next
但为什么我在MyDataGrid控件里的CheckBox选择几个,在页面上显示的都是“No”?也就是说取不到cb.Checked的值。