Friday, October 12, 2007

Identify the row of gridview (with checkbox column) whose checkbox checkchanged.

I'm currently working on an ASP.NET 2.0 project that uses a gridview with several checkboxes in the item templates, and we wanted to use the checkbox click event to modify appropriate data.
We need to respond to the checkbox change event, and identify which check box on which row fired the event.
Use the NamingContainer property of the accessed control and cast it to (GridViewRow).

/// <summary>
Handles the CheckedChanged event of the ItemSelectCheckBox control.
<param name="sender">The source of the event.</param>
<param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
void ItemSelectCheckBox_CheckedChanged(object sender, EventArgs e)


CheckBox checkBox = (CheckBox)sender;

GridViewRow row = (GridViewRow)checkBox.NamingContainer;




No comments:

Post a Comment

Creative Commons License
This work by Tito is licensed under a Creative Commons Attribution 3.0 Unported License.