RBS
asked on
Loop through Check boxes and perform action
Hi:
I have created a registration page in which I use a repeater to populate a list of check boxes showing the available controls. The code looks like this:
<asp:Repeater ID="UsersRoleList" runat="server">
<ItemTemplate>
<asp:CheckBox runat="server" ID="RoleCheckBox" AutoPostBack="false" Text='<%# DataBinder.Eval(Container. DataItem, "RoleName") %>'
/>
<br />
</ItemTemplate>
</asp:Repeater>
DataTable roles = Check30.h30DataAccess.Role s_Get();
UsersRoleList.DataSource = roles;
UsersRoleList.DataBind();
On pressing the submit button, I would like to iterate through the RoleCheckBox and if checked, add the user to the role - i.e. Roles.AddUserToRole(profil e.UserName , RoleCheckBox.Text) or something like that. Any help in doing this greatly appreciated.
rbs
I have created a registration page in which I use a repeater to populate a list of check boxes showing the available controls. The code looks like this:
<asp:Repeater ID="UsersRoleList" runat="server">
<ItemTemplate>
<asp:CheckBox runat="server" ID="RoleCheckBox" AutoPostBack="false" Text='<%# DataBinder.Eval(Container.
/>
<br />
</ItemTemplate>
</asp:Repeater>
DataTable roles = Check30.h30DataAccess.Role
UsersRoleList.DataSource = roles;
UsersRoleList.DataBind();
On pressing the submit button, I would like to iterate through the RoleCheckBox and if checked, add the user to the role - i.e. Roles.AddUserToRole(profil
rbs
foreach(RepeaterItem rptItem in ptProducts.Items)
{
CheckBox chk = (CheckBox) rptItem.FindControl("chk_S elect");
if(chk.Checked)
// do stuff here;
}
{
CheckBox chk = (CheckBox) rptItem.FindControl("chk_S
if(chk.Checked)
// do stuff here;
}
ASKER
dj_alik:
This does not seem to work. The name of my check box is RoleCheckBox - but name of the control on the client side would seem to be related to the value RoleName in the repeater. I have no idea where "chk_Select" comes from.
Can you show how you think this would work - using the names of controls I have used.
Thanks,
rbs
This does not seem to work. The name of my check box is RoleCheckBox - but name of the control on the client side would seem to be related to the value RoleName in the repeater. I have no idea where "chk_Select" comes from.
Can you show how you think this would work - using the names of controls I have used.
Thanks,
rbs
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window