我正在创建一个CheckBoxList,我会动态填充它。 我介入了代码并且似乎没有触及以下方法,我认为所选值属性的值始终为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";
}
答案 0 :(得分:0)
问题可能是您对page_load
事件具有约束力。
尝试在page load
但在!Page.IsPostBack
if(!Page.IsPostBack)
{
//bind here.
}
答案 1 :(得分:-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