检索Repeater中的checkbox

时间:2022-06-01 21:21:28
前台:
                    <asp:Repeater ID="RepeaterRole" runat="server">
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBoxRole" runat="server" Text='<%# Eval("LoweredRoleName")%>' />
                        </ItemTemplate>
                    </asp:Repeater>

 

后台:

                    for (int i = 0; i < RepeaterRole.Items.Count; i++)
                    {
                        CheckBox CheckBox1 = (CheckBox)RepeaterRole.Items[i].FindControl("CheckBoxRole");
                        if (CheckBox1.Checked == true) 
                        {
                            //
                            Roles.AddUserToRole(strName, CheckBox1.Text.Trim());
                        }
                    }