This is a migrated thread and some comments may be shown as answers.

RadGrid ItemDataBound Event Stops Another Event

3 Answers 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sem
Top achievements
Rank 1
Sem asked on 12 Aug 2011, 04:35 PM
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:

 

<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);
    }
}

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 18 Aug 2011, 08:25 AM
Hi Sem,

I tried to replicate the issue but I actually did not see how the two controls events are related? Why would Button_Click and NeedDataSource/ItemDataBound fire in the same request? Do you have ViewState disabled or the button rebinds the grid? Generally, there should not be such problem with the event sequence, so we will need to first replicate it in order to find out its cause.

All the best,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Alex
Top achievements
Rank 1
answered on 14 Apr 2013, 05:55 AM
Even I am also facing same issue on the Telerik RadGrid control. I have OnItemDataBound event at the grid level and OnItemsRequested event in the Combobox control level but when I put onitemDataBound in gridlevel my OnItemsRequested event not firing If I remove OnItemDataBound event It works fine. But  I want two events should be fire how do resolve this issue.
F
ind the code below

<telerik:RadGrid ID="RadGrid1"  GridLines="None" AutoGenerateColumns="false" AllowPaging="true"
                                        AllowSorting="true" CssClass="telerikgridstyle" runat="server" AllowAutomaticUpdates="false"
                                        AllowAutomaticInserts="True" ShowStatusBar="true" OnItemDataBound="OnItemDataBoundHandler"
                                        SkinID="gridviewSkin" OnNeedDataSource="RadGrid1_NeedDataSource" AllowCustomPaging="false">
                                        <MasterTableView ShowFooter="false" Name="MasterTableView1" DataKeyNames="AC_VISIT_ID" EditMode="InPlace"
                                            CommandItemDisplay="None" >
                                            <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" ShowExportToExcelButton="false"
                                                ShowExportToPdfButton="false" ShowExportToCsvButton="false"></CommandItemSettings>
                                            <HeaderStyle CssClass="telerikgridheader" />
                                            <Columns>
                                                <telerik:GridBoundColumn DataField="AC_VISIT_ID" Display="false" />
                                                <telerik:GridBoundColumn DataField="Foreign" ReadOnly="true" HeaderText="Int" HeaderStyle-Width="8px"
                                                    ItemStyle-Width="8px" />
<telerik:GridTemplateColumn DataField="MECH_STAFFNO1" HeaderText="AC Mech" HeaderStyle-Width="70px"
                                                    ItemStyle-Width="70px">
                                                    <ItemTemplate>
                                                        <%--EnableLoadOnDemand="True" AutoPostBack="true" OnItemsRequested="RCBAcMech_ItemsRequested" --%>
                                                        <telerik:RadComboBox runat="server" ID="RCBAcMech" DataTextField="EMP_SHORTNAME" EnableLoadOnDemand="True" AutoPostBack="true" 
                                                        OnItemsRequested="RCBAcMech_ItemsRequested"
                                                            EnableItemCaching="true" CausesValidation="false"  DataValueField="STAFFID" 
                                                            HighlightTemplatedItems="true" Height="140px" Width="77px" DropDownWidth="700px"
                                                            OnSelectedIndexChanged="RCBAcMech_OnSelectedIndexChangedHandler">
                                                            <HeaderTemplate>
                                                                <ul>
                                                                    <li class="col1">Name</li>
                                                                    <li class="col2">Staff No</li>
                                                                    <li class="col3">Shift Start</li>
                                                                    <li class="col4">Shift End</li>
                                                                </ul>
                                                            </HeaderTemplate>
                                                            <ItemTemplate>
                                                                <ul>
                                                                    <li class="col1">
                                                                        <%# DataBinder.Eval(Container, "Text")%>
                                                                    </li>
                                                                    <li class="col2">
                                                                        <%# DataBinder.Eval(Container, "Attributes['STAFFNO']")%>
                                                                    </li>
                                                                    <li class="col3">
                                                                        <%# DataBinder.Eval(Container, "Attributes['SHIFT_START']")%>
                                                                    </li>
                                                                    <li class="col4">
                                                                        <%# DataBinder.Eval(Container, "Attributes['SHIFT_END']")%>
                                                                    </li>
                                                                </ul>
                                                            </ItemTemplate>
                                                        </telerik:RadComboBox>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
</Columns>
                                        </MasterTableView>
                                        <ClientSettings>
                                            <%--<Selecting AllowRowSelect="True" />--%>
                                            <Scrolling AllowScroll="True" UseStaticHeaders="True" ScrollHeight="450px" EnableVirtualScrollPaging="True"
                                                SaveScrollPosition="True"></Scrolling>
                                            <%--<ClientEvents OnRowSelected="RowSelected" />--%>
                                        </ClientSettings>
                                    </telerik:RadGrid>

0
Maria Ilieva
Telerik team
answered on 17 Apr 2013, 12:42 PM
Hello Alex,

I tried to replicate the resented issue but to no avail. Find attached a sample runnable application which works correctly on my end. Test it on your side and verify what the difference in your case is.

Regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Sem
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Alex
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or