Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 62161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:25:57+00:00 2026-05-10T18:25:57+00:00

i’m want to have a repeater generate a bunch of checkboxes, e.g.: <tr><td><input type=checkbox

  • 0

i’m want to have a repeater generate a bunch of checkboxes, e.g.:

<tr><td><input type='checkbox' name='t' value='11cbf4deb87' /> <input type='checkbox' name='a' value='33cbf4deb87' />stackoverflow.com</td></tr> <tr><td><input type='checkbox' name='t' value='11cbf4deb88' /> <input type='checkbox' name='a' value='33cbf4deb87' />microsoft.com</td></tr> <tr><td><input type='checkbox' name='t' value='11cd3f33a89' /> <input type='checkbox' name='a' value='33cbf4deb87' />gmail.com</td></tr> <tr><td><input type='checkbox' name='t' value='1138fecd337' /> <input type='checkbox' name='a' value='33cbf4deb87' />youporn.com</td></tr> <tr><td><input type='checkbox' name='t' value='11009efdacc' /> <input type='checkbox' name='a' value='33bf4deb87' />fantasti.cc</td></tr> 

Question 1: How do i individually reference each checkbox when the repeater is running so i can set the unique value?

Do i data-bind it with something like:

<itemtemplate>    <tr>       <td>          <input type='checkbox' name='t'              value='<%# ((Item)Container.DataItem).TangoUniquifier %>' />          <input type='checkbox' name='a'              value='<%# ((Item)Container.DataItem).AlphaUniquifier %>' />          <%# ((Item)Container.DataItem).SiteName %>       </td>    </tr> </itemtemplate> 

Or am i supposed to set it somehow in the OnItemDataBound?

<asp:repeater id='ItemsRepeater'        OnItemDataBound='ItemsRepeater_OnItemDataBound' runat='server'>    ...    <itemtemplate>       <tr>          <td>             <input id='chkTango' type='checkbox' name='t' runat='server' />             <input id='chkAlpha' type='checkbox' name='a' runat='server' />             <%# ((Item)Container.DataItem).SiteName %>          </td>       </tr>    </itemtemplate>    ... </asp:repeater>   protected void ItemsRepeater_OnItemDataBound(object sender, RepeaterItemEventArgs e) {    // if the data bound item is an item or alternating item (not the header etc)    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)    {       // get the associated item       Item item = (Item)e.Item.DataItem;        //???       this.chkTango.Value = item.TangoUniquifier;       this.chkAlpha.Value = item.AlphaUniquifier;    } } 

But if i’m supposed to reference it in the code-behind, how do i reference it in the code-behind? Am i supposed to reference it using the (server-side) id property of an <INPUT> control? i realize that the ID of a control on the server-side is not the same as the ID that will be present on the client.

Or do i have to do something where i have to find an INPUT control with a name of ‘t’ and another with a name of ‘a’? And what kind of control is a CheckBox that allows me to set it’s input value?

protected void ItemsRepeater_OnItemDataBound(object sender, RepeaterItemEventArgs e) {    // if the data bound item is an item or alternating item (not the header etc)    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)    {       // get the associated item       Item item = (Item)e.Item.DataItem;        CheckBox chkTango = (CheckBox)e.Item.FindControl('chkTango');       chkTango.Value = item.TangoUniquifier;        CheckBox chkAlpha = (CheckBox)e.Item.FindControl('chkAlpha');       chkAlpha.Value = item.AlphaUniquifier;    } } 

Question 2: When the user later clicks SUBMIT, how do i find all the checked checkboxes, or more specifically their VALUES?

Do i have to FindControl?

protected void DoStuffWithLinks_Click(object sender, EventArgs e) {    // loop through the repeater items    foreach (RepeaterItem repeaterItem in actionItemRepeater.Items)    {       Item item = repeaterItem.DataItem as Item;        // grab the checkboxes       CheckBox chkAlpha = (CheckBox)repeaterItem.FindControl('chkAlpha');       CheckBox chkTango = (CheckBox)repeaterItem.FindControl('chkTango');        if (chkAlpha.Checked)       {                    item.DoAlphaStuff(chkAlpha.Name);       }        if (chkTango.Checked)       {          item.DoTangoStuff(chkTango.Name);       }    } } 

Is the repeater items DataItem still there on a click event handler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:25:57+00:00Added an answer on May 10, 2026 at 6:25 pm

    Use the server control instead of making an input control runat=server

     <asp:CheckBox id='whatever' runat='Server' /> 

    When you set the value in your ItemDataBound, you use FindControl

    CheckBox checkBox = (CheckBox)e.Item.FindControl('whatever'); checkBox.Checked = true; 

    When you get the items, you also use FindControl from the item in a foreach construct. Also, depending on how you databound it, the DataItem may no longer be there after a postback.

    foreach (RepeaterItem item in myRepeater.Items) {     if (item.ItemType == ListItemType.Item          || item.ItemType == ListItemType.AlternatingItem)      {          CheckBox checkBox = (CheckBox)item.FindControl('whatever');         if (checkBox.Checked)         { /* do something */ }     } } 
    • Many people are tempted to ‘safe cast’ using the as operator with FindControl(). I don’t like that because when you change the control name on the form, you can silently ignore a development error and make it harder to track down. I try to only use the as operator if the control isn’t guaranteed to be there.

    Update for: Which CheckBox is which? In the rendered html you’ll end up having all these checkbox name like

    ctl00_cph0_ParentContainer_MyRepeater_ctl01_MyCheckbox ctl00_cph0_ParentContainer_MyRepeater_ctl02_MyCheckbox ctl00_cph0_ParentContainer_MyRepeater_ctl03_MyCheckbox 

    You don’t care what the names are because the foreach item.FindControl() gets them for you, and you shouldn’t assume anything about them. However, when you iterate via foreach, you usually need a way to reference that back to something. Most of the time this is done by also having an asp:HiddenField control alongside each CheckBox to hold an identifier to match it back up to the correct entity.

    Security note: there is a security issue with using hidden fields because a hidden field can be altered in javascript; always be conscious that this value could have been modified by the user before the form was submitted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I would use 'http://domain.com' as my URL when generating the… May 11, 2026 at 3:23 pm
  • added an answer This would be a good starting point for serializing the… May 11, 2026 at 3:23 pm
  • added an answer Normalising URLs to a canonical form prior to insertion is… May 11, 2026 at 3:23 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.