Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to programmatically clear Checkbox
Message
 
To
28/04/2008 15:45:18
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01313608
Message ID:
01314150
Views:
11
This message has been marked as the solution to the initial question of the thread.
>Given the following HTML fragment, how can I clear the checkmark, in the checkbox with id = "checkAll", in code behind? I can get e reference to the containing grid with:
>
>
DirectCast(Page.FindControl("dgListItems"), DataGrid)
>
>but I can't figure out how to get a reference to the checkbox in the HeaderTemplate in the ColumnTemplate.
>

If you're doing this from an event of the checkbox, you can just use:
CheckBox check = sender as CheckBox;
if (check != null)
   check.Checked = true;
If it's from some other event handler, or just in something like a normal postback, you can't do this directly. Actually, I don't think they expose a FindControl for that kind of thing (at least, I didn't see one). You could do this yourself though by traversing the Controls collection of the grid:
CheckBox check = this.FindGridControl(this.grdSample.Controls, "checkAll") as CheckBox;
if (check != null)
    check.Checked = true;

protected Control FindGridControl(ControlCollection control, string controlName)
{
    Control matchingControl = null;

    foreach (Control subControl in control)
    {
        if (subControl.ClientID.EndsWith(controlName))
            return subControl;

        matchingControl = this.FindGridControl(subControl.Controls, controlName);
        if (matchingControl != null)
            break;
    }

    return matchingControl;
}
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform