I have used the ITemplate structure to dynamically create columns for RadGrid's -- and it works great for me for display purposes.
I am now trying to add a LinkButton and to process the event when it's clicked through the Grid's onItemCommand property. Although, when the linkbutton is clicked, the page postback happends, but the ItemCommand method is not triggered.
What's the missing link?
Thanks,
Todd.
grid html
The columns are created during the first Page_Load
Here is the template class
I am now trying to add a LinkButton and to process the event when it's clicked through the Grid's onItemCommand property. Although, when the linkbutton is clicked, the page postback happends, but the ItemCommand method is not triggered.
What's the missing link?
Thanks,
Todd.
grid html
<telerik:RadGrid ID="TimeSlotScheduleGrid" runat="server" EnableViewState="True" AutoGenerateColumns="False" Width="584" ShowFooter="false" onItemDataBound="TimeSlotScheduleGrid_RowDataBound" onItemCommand="TimeSlotScheduleGrid_RowCommand" OnColumnCreated="TimeSlotScheduleGrid_ColumnCreated"> <MasterTableView DataKeyNames="Id" GroupLoadMode="Client" Width="99%"> <GroupByExpressions> <telerik:GridGroupByExpression> <SelectFields> <telerik:GridGroupByField FieldName="GameNo" HeaderText="Game Number" HeaderValueSeparator=": " /> </SelectFields> <GroupByFields> <telerik:GridGroupByField FieldName="GameNo" SortOrder="Ascending" /> </GroupByFields> </telerik:GridGroupByExpression> </GroupByExpressions> <Columns> <telerik:GridTemplateColumn HeaderText='Time Slot'> <HeaderStyle Width="130" /> <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" /> <ItemTemplate> <asp:Label ID="timeSlotLabel" runat="server" /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> <ClientSettings EnableRowHoverStyle="false"> <Selecting AllowRowSelect="false" /> <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True" FrozenColumnsCount="1"/> </ClientSettings> </telerik:RadGrid>The columns are created during the first Page_Load
for (int wk = 1; wk < (maxWeeks + 1); wk++) { GridTemplateColumn templateColumn = new GridTemplateColumn(); string columnName = "W" + wk.ToString(); templateColumn.HeaderText = columnName; templateColumn.HeaderStyle.Width = new Unit(40); templateColumn.UniqueName = columnName; templateColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center; templateColumn.ItemStyle.VerticalAlign = VerticalAlign.Top; if(divisionObj.IsManualTimeSlotEntry) templateColumn.ItemTemplate = new TimeSlotCheckBoxTemplate(columnName); else templateColumn.ItemTemplate = new TimeSlotTemplate(columnName); TimeSlotScheduleGrid.MasterTableView.Columns.Add(templateColumn); } Here is the template class
private class TimeSlotTemplate : ITemplate { private string templateName; //controls private Label label; private LinkButton linkButton; private Image image; public TimeSlotTemplate(string name) { templateName = name; } public void InstantiateIn(System.Web.UI.Control container) { label = new Label(); label.ID = templateName + "Label"; linkButton = new LinkButton(); linkButton.ID = templateName + "Button"; image = new Image(); image.ID = templateName + "Image"; linkButton.Controls.Add(image); container.Controls.Add(label); container.Controls.Add(linkButton); } }