Link to home
Start Free TrialLog in
Avatar of RBS
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.Roles_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(profile.UserName, RoleCheckBox.Text) or something like that.  Any help in doing this greatly appreciated.

rbs
Avatar of ExpertHelp79
ExpertHelp79

you can manipulate the rest of the code
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
  CheckBox c = e.Row.Cells[4].FindControl("YourCheckboxId");
  if(c != null && e.Row.DataItem["sFixed_f"] == true)
  {
    c.Checked = true;
  }
}

Open in new window

foreach(RepeaterItem rptItem in ptProducts.Items)
 {
 CheckBox chk = (CheckBox) rptItem.FindControl("chk_Select");
 if(chk.Checked)
 // do stuff here;
 }
 
Avatar of RBS

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
ASKER CERTIFIED SOLUTION
Avatar of dj_alik
dj_alik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial