[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

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
0
RBS
Asked:
RBS
  • 2
1 Solution
 
ExpertHelp79Commented:
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

0
 
dj_alikCommented:
foreach(RepeaterItem rptItem in ptProducts.Items)
 {
 CheckBox chk = (CheckBox) rptItem.FindControl("chk_Select");
 if(chk.Checked)
 // do stuff here;
 }
 
0
 
RBSAuthor Commented:
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
0
 
dj_alikCommented:
please read this:
Getting Value out of a data repeater checkbox
http://www.velocityreviews.com/forums/t115593-getting-value-out-of-a-data-repeater-checkbox.html
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now