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

DetailTable contents of RadGrid lost on postback

3 Answers 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 15 Sep 2016, 01:34 PM

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?

 

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 19 Sep 2016, 08:18 AM
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.
0
Anders
Top achievements
Rank 1
answered on 20 Sep 2016, 12:24 PM
And the GridTableView will only need the data in one page access and persist it in further accesses?
0
Eyup
Telerik team
answered on 23 Sep 2016, 01:25 PM
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.
Tags
Grid
Asked by
Anders
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Anders
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or