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

Why isn't NeedDataSource being fired?

2 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 11 May 2017, 12:40 AM

I've got a combobox that updates a grid, but the grid's NeedDataSource handler isn't invoked when the AJAX request happens.  However, when I click the refresh button on the grid it issues another AJAX request and this one does invoke the NeedDataSource handler.  Can anyone help me understand why this isn't happening in the former case?

 

 

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Groups.aspx.cs" Inherits="BuildDashBoard.Groups" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="HeaderContent" ContentPlaceHolderID="HeadContent" runat="server"></asp:Content>
<asp:Content ID="NavigationMenu" ContentPlaceHolderID="NavigationMenuContent" runat="server"></asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
  <div>
    <telerik:radpanelbar ID="RadPanelBarConfigs" runat="server" Width="100%" AllowCollapseAllItems="True" PersistStateInCookie="True" CssClass="RadPanelBar_site">
      <Items>
        <telerik:RadPanelItem Text="Custom Groups" Expanded="True" Font-Bold="False" Font-Size="Medium" BackColor="#FFFF80" Enabled="true">
          <ContentTemplate>
            <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
              <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadComboBoxCustomGroups2">
                  <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGridGroupMembers" LoadingPanelID="RadAjaxLoadingPanel" />
                  </UpdatedControls>
                </telerik:AjaxSetting>
              </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel" runat="server" Skin="Default">
            </telerik:RadAjaxLoadingPanel>
            <asp:SqlDataSource ID="SqlDataSourceCustomGroups" runat="server"
                               ConnectionString="<%$ ConnectionStrings:BuildServicesConnectionString %>"
                               SelectCommand="sp_GetAllEditableCustomGroups" SelectCommandType="StoredProcedure"
                               InsertCommand="sp_AddCustomGroup" InsertCommandType="StoredProcedure"
                               UpdateCommand="sp_DeleteCustomGroup" UpdateCommandType="StoredProcedure">
              <InsertParameters>
                <asp:Parameter Name="CustomGroupName" Type="String" />
              </InsertParameters>
              <UpdateParameters>
                <asp:Parameter Name="CustomGroupId" Type="Int32" />
              </UpdateParameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSourceCustomGroupBranchesSource" runat="server"
                               ConnectionString="<%$ ConnectionStrings:BuildServicesConnectionString %>"
                               SelectCommand="sp_GetBranchesNotInCustomGroup" SelectCommandType="StoredProcedure">
              <SelectParameters>
                <asp:ControlParameter ControlID="RadComboBoxCustomGroups2" DefaultValue=""
                                      Name="GroupId" PropertyName="SelectedValue" Type="Int32" />
              </SelectParameters>
            </asp:SqlDataSource>
            <asp:Panel ID="CustomizeCustomGroupPanel" runat="server" GroupingText="Group members" Width="635px">
              <div>
                <div class="InlineTable">
                  <telerik:RadComboBox ID="RadComboBoxCustomGroups2" runat="server"
                                       DataSourceID="SqlDataSourceCustomGroups" DataTextField="Group_Name"
                                       DataValueField="Group_Id" CssClass="radcombobox" AutoPostBack="True" />
                </div>
              </div>
              <br />
              <div>
                <div>
                  <telerik:RadGrid ID="RadGridGroupMembers" runat="server" CssClass="RadGrid_site" ClientSettings-Selecting-AllowRowSelect="true"
                                   AutoGenerateColumns="false" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True" OnNeedDataSource="RadGridGroupMembers_NeedDataSource"
                                   OnUpdateCommand="RadGridGroupMembers_UpdateCommand" OnInsertCommand="RadGridGroupMembers_InsertCommand">
                    <MasterTableView CommandItemDisplay="Top" EditMode="InPlace" DataKeyNames="Branch_Id">
                      <Columns>
                        <telerik:GridEditCommandColumn />
                        <telerik:GridBoundColumn DataField="Branch_Id" HeaderText="Branch ID" UniqueName="Branch_Id" ReadOnly="true" Display="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn HeaderText="Branch Name" UniqueName="Branch_Name">
                          <EditItemTemplate>
                            <asp:DropDownList ID="ddl_branch_name" runat="server" DataValueField="Branch_Name" DataSourceId="SqlDataSourceCustomGroupBranchesSource">
                            </asp:DropDownList>
                          </EditItemTemplate>
                          <ItemTemplate>
                            <asp:Literal runat="server" Text='<%# Eval("Branch_Name") %>'>
                            </asp:Literal>
                          </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridDateTimeColumn DataField="Expiration" HeaderText="Expiration" UniqueName="Expiration" ReadOnly="false">
                        </telerik:GridDateTimeColumn>
                      </Columns>
                    </MasterTableView>
                  </telerik:RadGrid>
                </div>
              </div>
            </asp:Panel>
          </ContentTemplate>
        </telerik:RadPanelItem>
      </Items>
    </telerik:radpanelbar>
  </div>
</asp:Content>

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 15 May 2017, 12:39 PM

Hi,

If you need to refresh the data in the grid, call its .Rebind() method, otherwise old data will be taken from the ViewState. You can do that in the SelectedIndexChanged event of the combo box.

Regards,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Craig
Top achievements
Rank 1
answered on 18 May 2017, 07:35 PM
Thanks Marin, that did the trick!  I had found a way to make it work by wrapping the grid in an update panel, triggering an ajax request from the combobox's close event handler and then calling then rebinding the grid inside the ajax manager's ajax request handler.  Fortunately, I was able to do away with all of that after trying your suggestion.
Tags
Grid
Asked by
Craig
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Craig
Top achievements
Rank 1
Share this question
or