Hi,
Scenario:-
I have a web page with a listing of items. besides each item is a checkbox. At the top of the page is a delete button. User selects his items to delete and presses delete button.
Problem:-
My codebehind should cycle through each control on page, if its a checkbox and its checked get the ID of the checkbox.
However it doesn't work.
Code:-
private void isCheckedAndAdd(Control ctrl)
{
if (ctrl is CheckBox && ((CheckBox)ctrl).Checked)
{
///Do your stuff with a checked Checkbox.
string sAccomodationId = ctrl.ID.ToString();
}
foreach (Control c in ctrl.Controls)
{
isCheckedAndAdd(c);
}
}
protected void Delete_OnClick(object sender, EventArgs e)
{
isCheckedAndAdd(this);
}
Questions:-
1. Is this the best way to do this?
2. Any ideas why this doesn't work?
Regards
Scenario:-
I have a web page with a listing of items. besides each item is a checkbox. At the top of the page is a delete button. User selects his items to delete and presses delete button.
Problem:-
My codebehind should cycle through each control on page, if its a checkbox and its checked get the ID of the checkbox.
However it doesn't work.
Code:-
private void isCheckedAndAdd(Control ctrl)
{
if (ctrl is CheckBox && ((CheckBox)ctrl).Checked)
{
///Do your stuff with a checked Checkbox.
string sAccomodationId = ctrl.ID.ToString();
}
foreach (Control c in ctrl.Controls)
{
isCheckedAndAdd(c);
}
}
protected void Delete_OnClick(object sender, EventArgs e)
{
isCheckedAndAdd(this);
}
Questions:-
1. Is this the best way to do this?
2. Any ideas why this doesn't work?
Regards