Hi,
I have a user control that contains a RadGrid and a RadToolBar control. The RadGrid uses the NeedDataSource event to populate its content. The RadToolBar contains a button that inits a postback to save the contents of the page (the page contains other controls such as drop down list , text box, etc. but none are related to the issue I am having). In its current state (code shown below) everything works fine (the RadToolBar ButtonClick event handler get called and the content on the page is saved). The problem occurs when I add an event handler for the RadGrid's ItemDataBound event. I use this handler to set the PostBackUrl of an Button control (I do it on this event because I need the ID of the RadGrid's row content). The problem is that the RadToolBar ButtonClick event handler doesn't get called anymore.
With everything working, the event sequence is: Load -> NeedDataSource -> ButtonClick. After adding the ItemDataBound event the sequence is Load -> NeedDataSource -> ItemDataBound (the ButtonClick event gets "ignored").
Why does adding the ItemDataBound event in the RadGrid affect the ButtonClick event in the RadToolBar? How can I get the ButtonClick event to "not be ignored" while still maintaining the ItemDataBound event?
Thanks. (Please see code below)
When Things Work Fine:
I have a user control that contains a RadGrid and a RadToolBar control. The RadGrid uses the NeedDataSource event to populate its content. The RadToolBar contains a button that inits a postback to save the contents of the page (the page contains other controls such as drop down list , text box, etc. but none are related to the issue I am having). In its current state (code shown below) everything works fine (the RadToolBar ButtonClick event handler get called and the content on the page is saved). The problem occurs when I add an event handler for the RadGrid's ItemDataBound event. I use this handler to set the PostBackUrl of an Button control (I do it on this event because I need the ID of the RadGrid's row content). The problem is that the RadToolBar ButtonClick event handler doesn't get called anymore.
With everything working, the event sequence is: Load -> NeedDataSource -> ButtonClick. After adding the ItemDataBound event the sequence is Load -> NeedDataSource -> ItemDataBound (the ButtonClick event gets "ignored").
Why does adding the ItemDataBound event in the RadGrid affect the ButtonClick event in the RadToolBar? How can I get the ButtonClick event to "not be ignored" while still maintaining the ItemDataBound event?
Thanks. (Please see code below)
When Things Work Fine:
<telerik:RadToolBar ID="RadToolBar1" runat="server" Skin="Web20" style="width:100%;" OnButtonClick="RadToolBar1_ButtonClick"> <Items> <telerik:RadToolBarButton ImageUrl="~/[path_omitted]/SaveRadToolBar1.png" Text="Save" ToolTip="Save" /> </Items> </telerik:RadToolBar>
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Vista" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"> <MasterTableView CommandItemDisplay="None" Height="30" DataKeyNames="ID" ClientDataKeyNames="ID" GroupLoadMode="Client" NoMasterRecordsText="You do not have any data"> <GroupByExpressions>
<telerik:GridGroupByExpression> <GroupByFields> <telerik:GridGroupByField FieldName="Topic.Category.Name" /> </GroupByFields> <SelectFields> <telerik:GridGroupByField FieldName="Topic.Category.Name" HeaderText="Category" /> </SelectFields> </telerik:GridGroupByExpression> </GroupByExpressions> <Columns> <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="DataID" Visible="false" /> <telerik:GridBoundColumn DataField="Topic.ID" UniqueName="DataTopicID" Visible="false" /> <telerik:GridBoundColumn DataField="Topic.Category.Name" HeaderText="Name" UniqueName="DataCategoryName" Visible="false" /> <telerik:GridBoundColumn DataField="Topic.Name" HeaderText="Topic" UniqueName="DataTopicName" /> <telerik:GridTemplateColumn HeaderText="Go" UniqueName="DataGoTo" HeaderStyle-Width="50"> <ItemTemplate> <asp:Button ID="ButtonGoTo" runat="server" ToolTip="Go to data" Text="Go" /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid>
When the RadToolBar ButtonClick Event Gets Ignored:
<telerik:RadGrid ID="RadGrid1" runat="server"Skin="Vista"AutoGenerateColumns="false"OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound"> <MasterTableView CommandItemDisplay="None" Height="30" DataKeyNames="ID" ClientDataKeyNames="ID" GroupLoadMode="Client" NoMasterRecordsText="You do not have any data"> <GroupByExpressions> <telerik:GridGroupByExpression> <GroupByFields> <telerik:GridGroupByField FieldName="Topic.Category.Name" /> </GroupByFields> <SelectFields> <telerik:GridGroupByField FieldName="Topic.Category.Name" HeaderText="Category" /> </SelectFields> </telerik:GridGroupByExpression> </GroupByExpressions> <Columns> <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="DataID" Visible="false" /> <telerik:GridBoundColumn DataField="Topic.ID" UniqueName="DataTopicID" Visible="false" /> <telerik:GridBoundColumn DataField="Topic.Category.Name" HeaderText="Name" UniqueName="DataCategoryName" Visible="false" /> <telerik:GridBoundColumn DataField="Topic.Name" HeaderText="Topic" UniqueName="DataTopicName" /> <telerik:GridTemplateColumn HeaderText="Go" UniqueName="DataGoTo" HeaderStyle-Width="50"> <ItemTemplate> <asp:Button ID="ButtonGoTo" runat="server" ToolTip="Go to data" Text="Go" /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem dataItem = e.Item as GridDataItem; (dataItem["DataGoTo"].FindControl("ButtonGoTo") as Button) .PostBackUrl = String.Format( "~/ShowData.aspx?id={0}", dataItem["DataTopicID"].Text); } }