Adding Event Handlers within datagrid
Posted on 2006-05-22
I have a datagrid that will only ever have a single record.
I want to call an event when a checkbox is checked/unchecked that will display extra fields.
I have scoured the forums for a solution to this. I feel sure it must be possible.
I just don't seem to be able to find a way to get a reference to the controls within the datagrid (unless i am using one of the datagrids built in commands - update,delete etc)
I have got this far.
This is the function i am calling from the grid.
public void showEmailReminderInfo_CheckChanged(object s, DatagridItemEventArgs e)
Panel pnlEmailReminderInfo = ((Panel)e.Item.FindControl("pnlEmailReminderInfo"));
CheckBox chkEmailAlert = ((CheckBox)e.Item.FindControl("chkEmailAlert"));
pnlEmailReminderInfo.Visible = false;
pnlEmailReminderInfo.Visible = true;
This is how I have added the event handler to the datagrid.
// datagrid item event
private void datagrid_ItemCreated(object s, DataGridItemEventArgs e)
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
CheckBox cb = ((CheckBox)e.Item.Cells.FindControl("CheckBoxID"));
cb.CheckedChanged += new EventHandler(this.showEmailReminderInfo_CheckChanged);
I've really no idea if this is correct or not. I seem to have been going backwards and forwards with different methods for an age.
Any help very much appreciated.