复选框列表事件未触发

时间:2016-10-20 09:05:54

标签: asp.net

我在面板中有一个下拉列表和一个复选框列表。在下拉列表选择中,将加载复选框列表。在选中复选框列表项时,复选框的OnselectedIndexChanged事件未触发。而不是下拉列表的OnselectedIndexChanged事件正在调用。

请找到以下代码

<asp:UpdatePanel ID="UpdatePanel1" runat="server" >             
                    <ContentTemplate>                    
                    <asp:Panel ID="pnldivchkbolst" runat="server" Visible="false">                           


                        <asp:Label ID="lblsupervisor" runat="server" Text="Allocate Supervisor :"></asp:Label>
                        <asp:DropDownList ID="ddlSupervisor" AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddlSupervisor_SelectedIndexChanged">
                        </asp:DropDownList>                  

                        <p>
                            <asp:Label ID="Label1" runat="server" Text="Selected Students :"></asp:Label>

                            <asp:Label ID="selectitems" runat="server" Text=""></asp:Label>
                        </p>

                        <asp:CheckBoxList runat="server" ID="chkstudentlist"  AutoPostBack="true"  
                            OnSelectedIndexChanged="chkstudentlist_SelectedIndexChanged" >
                        </asp:CheckBoxList>             


                        <p>
                            <asp:Button runat="server" ID="btnSubmit" CssClass="button1" Text="Submit" OnClick="Submit_SSL_Click" />
                            <asp:Button runat="server" ID="btnEditSupervisor" CssClass="button1" Visible="false"
                                Text="Edit Supervisor" OnClick="btnEditSupervisor_Click" />

                            <asp:Button runat="server" ID="btnUnSelect" CssClass="button1" Text="UnSelect"
                                OnClick="btnUnSelect_Click" />
                            <asp:Label ID="lblUnselect" runat="server" Text=""></asp:Label>

                        </p>
                        <tr>
                            <asp:Label ID="Label3" runat="server" Text="Note: Student Listed in Yellow color have not completed the previous Activity and Students with pink Color are already assinged to   Supervisor"></asp:Label>
                        </tr>
                    </asp:Panel>
                    </ContentTemplate>                   
                    </asp:UpdatePanel>

在Page_Init方法中,我有一个动态创建的tabcontainer并在该选项卡中添加了pnldivchkbolst面板。

提前致谢。

1 个答案:

答案 0 :(得分:0)

复选框列表 OnSelectedIndexChanged 属性会引发 SelectedIndexChanged 事件。在这种情况下,您需要通过复选框列表项进行交互,并检查所选属性是否已设置为true,以确定选择了哪个项目。例如:

protected void CheckBoxList1_SelectedIndexChnaged(object sender, System.EventArgs e)
{
    foreach (ListItem item in CheckBoxList1.Items)
    {
        if (item.Selected == true)
        {
            // this is the one selected by the user
        }
    }
}