A
AC
I've created a user control (ASCX) that contains two buttons. This control is programatically placed into a datagrid via the LoadTemplate method and the TemplateColumn object. What I'd like to do is attach events to the two buttons from the code that loaded the object... like so (any ideas... I know FindControl won't work... just don't/can't create the events from within the sort column):
SortColumn.ascx
<asp:button id="SortUp" runat="server" text="up" CommandName="SortUp"></asp:button>
<asp:button id="SortDown" runat="server" text="down" CommandName="SortDown"></asp:button>
ProgramaticDataGrid.aspx.cs
ITemplate sortColumnTemplate = Page.LoadTemplate("~/Controls/Templates/SortColumn.ascx");
// below doesn't work, but you see where i'm going
Button bUp = (Button)sortColumn.FindControl("SortUp");
bUp.Click += //event handler code
// above doesn't work, but you see where i'm going
TemplateColumn tc = new TemplateColumn();
tc.HeaderText = "Sorting";
tc.ItemTemplate = sortColumnTemplate;
DataGrid1.Columns.Add(tc);
// binding code next
SortColumn.ascx
<asp:button id="SortUp" runat="server" text="up" CommandName="SortUp"></asp:button>
<asp:button id="SortDown" runat="server" text="down" CommandName="SortDown"></asp:button>
ProgramaticDataGrid.aspx.cs
ITemplate sortColumnTemplate = Page.LoadTemplate("~/Controls/Templates/SortColumn.ascx");
// below doesn't work, but you see where i'm going
Button bUp = (Button)sortColumn.FindControl("SortUp");
bUp.Click += //event handler code
// above doesn't work, but you see where i'm going
TemplateColumn tc = new TemplateColumn();
tc.HeaderText = "Sorting";
tc.ItemTemplate = sortColumnTemplate;
DataGrid1.Columns.Add(tc);
// binding code next