Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 12, 2010 01:44 AM by decker dong - msft
Member
4 Points
74 Posts
Jul 08, 2010 05:05 PM|LINK
Hi All,
I tried some of the example from the web, but all of them will check/uncheck all the checkboxes in the form, NOT only in the repeater. Is there a way to implement this and only apply to repeater.
Thanks.
All-Star
16323 Points
2595 Posts
Jul 08, 2010 05:10 PM|LINK
You can do something like this:
foreach (RepeaterItem item in Repeater1.Items) { CheckBox cb = (CheckBox)item.FindControl("CheckBox1"); if (cb != null) { cb.Checked = true; //cb.Checked = false; } }
where the ID of the checkbox in your repeater is "CheckBox1".
53942 Points
8147 Posts
Jul 08, 2010 05:12 PM|LINK
you can try this:
using System.Linq; repeater.Items.OfType<RepeaterItem>().ToList().ForEach(a=>((CheckBox)a.FindControl("CheckBoxID")).Checked=true); repeater.Items.OfType<RepeaterItem>().ToList().ForEach(a => ((CheckBox)a.FindControl("CheckBoxID")).Checked = false);
Jul 08, 2010 05:40 PM|LINK
Should I put this on OnCheckedChanged event?
Jul 08, 2010 05:44 PM|LINK
r12345 Should I put this on OnCheckedChanged event?
if that's where you want to check/uncheck all the checkboxes, yes.
You'll need to set AutoPostBack="true".
118619 Points
18779 Posts
Jul 12, 2010 01:44 AM|LINK
Now please look at the whole sample:
http://codeasp.net/blogs/raghav_khunger/microsoft-net/622/check-uncheck-all-checkboxes-in-repeater
r12345
Member
4 Points
74 Posts
Check/Unchecked All CheckBoxes in Repeater
Jul 08, 2010 05:05 PM|LINK
Hi All,
I tried some of the example from the web, but all of them will check/uncheck all the checkboxes in the form, NOT only in the repeater. Is there a way to implement this and only apply to repeater.
Thanks.
rivdiv
All-Star
16323 Points
2595 Posts
Re: Check/Unchecked All CheckBoxes in Repeater
Jul 08, 2010 05:10 PM|LINK
You can do something like this:
foreach (RepeaterItem item in Repeater1.Items) { CheckBox cb = (CheckBox)item.FindControl("CheckBox1"); if (cb != null) { cb.Checked = true; //cb.Checked = false; } }
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> foreach (RepeaterItem item in Repeater1.Items)</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> CheckBox cb = (CheckBox)item.FindControl("CheckBox1");</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> cb.Checked = true;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> //cb.Checked = false;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div>where the ID of the checkbox in your repeater is "CheckBox1".
sansan
All-Star
53942 Points
8147 Posts
Re: Check/Unchecked All CheckBoxes in Repeater
Jul 08, 2010 05:12 PM|LINK
you can try this:
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">using System.Linq;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> repeater.Items.OfType<RepeaterItem>().ToList().ForEach(a=>((CheckBox)a.FindControl("CheckBoxID")).Checked=true);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> repeater.Items.OfType<RepeaterItem>().ToList().ForEach(a => ((CheckBox)a.FindControl("CheckBoxID")).Checked = false);</div>using System.Linq; repeater.Items.OfType<RepeaterItem>().ToList().ForEach(a=>((CheckBox)a.FindControl("CheckBoxID")).Checked=true); repeater.Items.OfType<RepeaterItem>().ToList().ForEach(a => ((CheckBox)a.FindControl("CheckBoxID")).Checked = false);r12345
Member
4 Points
74 Posts
Re: Check/Unchecked All CheckBoxes in Repeater
Jul 08, 2010 05:40 PM|LINK
Should I put this on OnCheckedChanged event?
rivdiv
All-Star
16323 Points
2595 Posts
Re: Check/Unchecked All CheckBoxes in Repeater
Jul 08, 2010 05:44 PM|LINK
if that's where you want to check/uncheck all the checkboxes, yes.
You'll need to set AutoPostBack="true".
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Check/Unchecked All CheckBoxes in Repeater
Jul 12, 2010 01:44 AM|LINK
Now please look at the whole sample:
http://codeasp.net/blogs/raghav_khunger/microsoft-net/622/check-uncheck-all-checkboxes-in-repeater