1

我正在创建一个 CheckBoxList 并动态填充它。我单步执行了代码,它似乎并没有命中以下方法,我认为 selected value 属性的值始终为 false。

<form id="form1" action="web_page.aspx">
   <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"
           onselectedindexchanged="CheckBoxList1_SelectedIndexChanged" >
   </asp:CheckBoxList>
   <br />
   <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="submit"/>
</form>
<div id="p" runat="server"></div>

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
    this.p.InnerHtml = "hello";
}
4

2 回答 2

0

问题可能是您对page_load事件具有约束力。

试着把它绑在page load里面!Page.IsPostBack

 if(!Page.IsPostBack)
 {
     //bind here.
 }
于 2013-03-28T12:57:50.850 回答
-1

您应该能够将发件人转换为复选框列表,然后遍历项目:

  Protected Sub test(ByVal sender As Object, ByVal e As EventArgs) Handles check1.SelectedIndexChanged
    Dim myCb As New CheckBoxList
    myCb = Me.check1

    For Each c As ListItem In myCb.Items
        Dim isChecked, value, text As String
        isChecked = c.Selected
        If (isChecked = True) Then
            value = c.Value
            text = c.Text
        End If
    Next
End Sub
于 2013-03-28T11:31:18.997 回答