How to get the values of HTML checkboxes within a Repeater using C#

If you want to read in a bunch of HTML checkboxes that are in a repeater using C# then you need to add a runat="server" element to you checkbox input tag. For example:

In your code behind you can now read in this element by using the following code:

using System.Web.UI.HtmlControls;

foreach (RepeaterItem currentControl in MyRepaterList.Items)
{
   HtmlInputCheckBox MyCheckBox = new HtmlInputCheckBox();
   MyCheckBox = (HtmlInputCheckBox)currentControl.FindControl("CheckboxName");
   if (MyCheckBox.Checked)
   {
      //logic if checkbox is ticked here
   }
}

The above code will loop through all the HTML checkbox elements within your repeater. You can easily modify this to let you look for HTML textboxes (HtmlInputText), HTML radio buttons (HtmlInputRadioButton), etc.

blog comments powered by Disqus

Get In Touch

Follow me online at TwitterFacebook or Flickr.

Latest Tweets