views:

1086

answers:

2

Reset checkboxes in datalist on click of button that is outside of datalist using c#

A: 

In the eventhandler for the buttons OnClick event you'd loop trough each item in the datalist and find the checkbox and reset it.

Sani Huttunen
foreach (DataListItem item in DataList1){ }when i try like this it shows error. Plz provide me the source code.thanks
Yogini
you should use foreach(DataListItem item in DataList1.Items){}
Sani Huttunen
A: 

What CKret said and also, I often find the Enumerable.OfType Method method very useful to do things like that. Looping through components of some type in a collection of some sort. For example, somewhere I do something like this:

foreach(CheckBox c in somePanel.Controls.OfType<CheckBox>())
{
    c.Checked = false;
}
Svish
If I want to check whether atleast one checkbox is selected using javascript then how to do that?
Yogini
javascript I don't know so well. In C# you can use the Any method like this: if(somePanel.Controls.OfType<CheckBox>().Any(ø => ø.Checked))
Svish