DetailTable contents of RadGrid lost on postback

4 posts, 0 answers
  1. Ingemar
    Ingemar avatar
    17 posts
    Member since:
    Apr 2012

    Posted 15 Sep Link to this post

    I have a RadGrid with a DetailTableView. I populate a detail table in the OnDetailTableDataBind handler when the node is expanded.
    However, when I postback the page, the DetailTableViews data will be empty.
    Is there a way to persist the data?
    I have tried to set ViewStateMode="Enabled" on the GridTableView.
    The attached screenshot1.png depicts the grid after I have populated the detail table:

    When I have changed the starttime for the RadGrid table item, the detail table is now emptied.

    The attached screenshot2.png shows what it will look like.

    Here is the declaration of the RadGrid:

    <telerik:RadGrid ID="grd" AutoGenerateColumns="False"
      OnDetailTableDataBind="grdActivitiesToCopy_OnDetailTableDataBind"
      AllowMultiRowSelection="True" runat="server" ViewStateMode="Enabled">
      <MasterTableView>
        <Columns>
          <telerik:GridClientSelectColumn UniqueName="DetailCheckColumn" />
          <telerik:GridBoundColumn HeaderText="Date" DataField="StartDay"/>
          <telerik:GridBoundColumn HeaderText="Time" DataField="TimeInterval"/>
          <telerik:GridBoundColumn DataField="EventName" HeaderText="Activity"/>
          <telerik:GridTemplateColumn HeaderText="New starttime">
            <ItemTemplate>
              <telerik:RadDateTimePicker runat="server" SelectedDate='<%#Eval("DateStart") %>'
                AutoPostBackControl="Both"
                OnSelectedDateChanged="GrdActivities_OnStartDateChanged"/>
            </ItemTemplate>
          </telerik:GridTemplateColumn>
          <telerik:GridTemplateColumn HeaderText="New endtime">
            <ItemTemplate>
              <telerik:RadDateTimePicker ID="endDateTime" runat="server"
                SelectedDate='<%#Eval("DateEnd") %>'/>
            </ItemTemplate>                       
          </telerik:GridTemplateColumn>
        </Columns>
        <DetailTables>
          <telerik:GridTableView ShowHeadersWhenNoRecords="True" Name="Child"/>
        </DetailTables>
      </MasterTableView>
      <ClientSettings
        <Selecting AllowRowSelect="true"/> 
      </ClientSettings
    </telerik:RadGrid>

    grdActivitiesToCopy_OnDetailTableDataBind is called when the item is expanded (every time). I would prefer to have the detail tables populated in the Page_Load event.
    Is that possible?

     

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 19 Sep Link to this post

    Hi,

    For your scenario it is recommended to use NeedDataSource and DetailTableDataBind events to populate the grid with data. The events should be raised automatically when a GridTableView needs the data.

    With that said, would you elaborate on what is the functionality you would like to implement? What is the server-side logic executed in the OnSelectedDateChanged handler?

    Regards,
    Viktor Tachev
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ingemar
    Ingemar avatar
    17 posts
    Member since:
    Apr 2012

    Posted 20 Sep in reply to Viktor Tachev Link to this post

    And the GridTableView will only need the data in one page access and persist it in further accesses?
  5. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 23 Sep Link to this post

    Hi Ingemar,

    This depends on the chosen HierarchyLoadMode:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/hierarchical-grid-types-and-load-modes/hierarchy-load-modes

    All the data is fetched when using ServerBind and Client options:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/hierarchy/hiding-the-expand-collapse-images-when-no-records

    As Victor have stated, performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:

    Declarative DataSource (DataSourceID property)
    Programmatic Data Binding (NeedDataSource event, + DetailTableDataBind for hierarchy). You should set the DataSource property ONLY within these event handlers.

    I hope this will prove helpful.

    Regards,
    Eyup
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top