Scenario:
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.
Riddle:
We need to respond to the checkbox change event, and identify which check box on which row fired the event.
Solution:
Use the NamingContainer property of the accessed control and cast it to (GridViewRow).
/// <summary>
/// Handles the CheckedChanged event of the ItemSelectCheckBox control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
protected void ItemSelectCheckBox_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
GridViewRow row = (GridViewRow)checkBox.NamingContainer;
...............................................
}
Reference:
http://www.geekswithblogs.net/sgreenberger/archive/2004/11/12/14871.aspx
No comments:
Post a Comment