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

NeedDataSource and Paging

6 Answers 253 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luciano Vernaschi
Top achievements
Rank 1
Luciano Vernaschi asked on 28 Sep 2011, 09:52 AM
Hi, I'm using NeedDataSource since I need to change the criteria according to selection in other controls. So I recreate a data source when conditions change and I do that in the NeedDataSource event handler. It works, but the pager does not update: if the previous criteria had, say, 25 records, it needed 3 pages, but if the new criteria returns 40 records, the pager sticks to 3, and only when I use it once, it updates to the new correct size of 4 pages.

I'm using the 3.5 version. How can I "help" the pager to make it update immediately?

6 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 28 Sep 2011, 11:16 AM
Hi Luciano,

Can you share the whole page code behind for further check? Basically, after calling Rebind() for the grid, the NeedDataSource event should fire and the grid pager should be automatically updated. Though if you have implemented custom paging, make sure you are updating the VirtualItemCount property in the NeedDataSource event handler.

Best wishes,
Iana Tsolova
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
0
Luciano Vernaschi
Top achievements
Rank 1
answered on 28 Sep 2011, 11:48 AM
Hi Iana, thank you for your reply. This is the full page, clearly incomplete since I'm working on it right now:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/principale.master"
    AutoEventWireup="true" CodeFile="Polizze.aspx.cs" Inherits="Archivi_Polizze" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
        .rgEditForm
        {
            width: auto !important;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <ClientEvents OnRequestStart="onRequestStart" />
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel2" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid2">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel2" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True"
            Height="480px" AllowSorting="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
            AllowPaging="True" DataSourceID="PolizzeDS" OnItemUpdated="RadGrid1_ItemUpdated"
            AllowFilteringByColumn="True" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted"
            OnDataBound="RadGrid1_DataBound" AutoGenerateColumns="False" CellSpacing="0" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
            <ClientSettings EnablePostBackOnRowClick="true">
                <Selecting AllowRowSelect="True" />
                <Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
                <Resizing AllowColumnResize="true" />
            </ClientSettings>
            <ExportSettings ExportOnlyData="True">
            </ExportSettings>
            <ValidationSettings EnableValidation="true" />
            <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="ID_POLI" DataSourceID="PolizzeDS"
                EditMode="Popup" HorizontalAlign="NotSet" Width="100%">
                <CommandItemSettings ShowExportToExcelButton="True" />
                <Columns>
                    <telerik:GridBoundColumn DataField="ID_POLI" DataType="System.Int32" HeaderText="Codice"
                        SortExpression="ID_POLI" UniqueName="ID_POLI" ReadOnly="true">
                        <HeaderStyle Width="120px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ID_ASSIC" HeaderText="Assicurato" SortExpression="ID_ASSIC"
                        UniqueName="ID_ASSIC" ReadOnly="true">
                        <HeaderStyle Width="120px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn DataField="ID_ASSIC" HeaderText="Anagrafica" UniqueName="ANAGRAFICA"
                        AllowFiltering="false">
                        <HeaderStyle Width="185px" />
                        <ItemTemplate>
                            <asp:Label runat="server" Text='<%# Eval("ARS_ASSICURATI.ARS_ANAGRAFICI.ANAG") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadComboBox ID="rcbASSIC" runat="server" DataSourceID="AssicuratiDS" DataValueField="ID_ASSIC"
                                OnItemDataBound="rcbASSIC_ItemDataBound" SelectedValue='<%#Bind("ID_ASSIC") %>'>
                            </telerik:RadComboBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="ID_POLATT" HeaderText="Polizza Attiva" SortExpression="ID_POLATT"
                        UniqueName="ID_POLATT">
                        <HeaderStyle Width="160px" />
                        <ItemTemplate>
                            <asp:Label runat="server" Text='<%# Eval("ID_POLATT") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadComboBox ID="rcbPOLATT" runat="server" DataSourceID="PolizzeAttiveDS"
                                DataValueField="ID_POLATT" OnItemDataBound="rcbPOLATT_ItemDataBound" SelectedValue='<%#Bind("ID_POLATT") %>'>
                            </telerik:RadComboBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="ID_POLATT" HeaderText="Area" UniqueName="POLATT_AREA"
                        AllowFiltering="false">
                        <HeaderStyle Width="160px" />
                        <ItemTemplate>
                            <asp:Label runat="server" Text='<%# Eval("ARS_POLIZZEATTIVE.AREA") %>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="ID_POLATT" HeaderText="Paese" UniqueName="POLATT_PAESE"
                        AllowFiltering="false">
                        <HeaderStyle Width="160px" />
                        <ItemTemplate>
                            <asp:Label runat="server" Text='<%# Eval("ARS_POLIZZEATTIVE.PAESE") %>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="DATAAPERTURA" HeaderText="Data Apertura" SortExpression="DATAAPERTURA"
                        UniqueName="DATAAPERTURA">
                        <HeaderStyle Width="160px" />
                        <ItemTemplate>
                            <asp:Label runat="server" Text='<%# Eval("DATAAPERTURA", "{0:d}") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadDatePicker ID="rdpDATAAPERTURA" runat="server" DateInput-CssClass="fldRequired"
                                DbSelectedDate='<%# Bind("DATAAPERTURA") %>'>
                            </telerik:RadDatePicker>
                            <asp:RequiredFieldValidator ControlToValidate="rdpDATAAPERTURA" ErrorMessage="*"
                                runat="server" Display="Dynamic" />
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridDateTimeColumn DataField="DATAESTINZIONE" HeaderText="Data Estinzione"
                        SortExpression="DATAESTINZIONE" UniqueName="DATAESTINZIONE" DataFormatString="{0:dd/MM/yyyy}"
                        ReadOnly="true">
                        <HeaderStyle Width="160px" />
                    </telerik:GridDateTimeColumn>
                    <telerik:GridDateTimeColumn DataField="DATABLOCCO" HeaderText="Data Blocco" SortExpression="DATABLOCCO"
                        UniqueName="DATABLOCCO" DataFormatString="{0:dd/MM/yyyy}" ReadOnly="true">
                        <HeaderStyle Width="160px" />
                    </telerik:GridDateTimeColumn>
                    <telerik:GridBoundColumn DataField="MOTIVO" HeaderText="Motivo" SortExpression="MOTIVO"
                        UniqueName="MOTIVO">
                        <HeaderStyle Width="130px" />
                    </telerik:GridBoundColumn>
                </Columns>
                <EditFormSettings>
                    <FormTableItemStyle Wrap="False" />
                    <FormCaptionStyle CssClass="EditFormHeader" />
                    <FormMainTableStyle BackColor="White" CellPadding="3" CellSpacing="0" GridLines="None"
                        Width="100%" />
                    <FormTableStyle BackColor="White" CellPadding="2" CellSpacing="0" Height="110px" />
                    <FormTableAlternatingItemStyle Wrap="False" />
                    <EditColumn ButtonType="ImageButton" CancelText="Cancel edit" UniqueName="EditCommandColumn1">
                    </EditColumn>
                    <FormTableButtonRowStyle CssClass="EditFormButtonRow" HorizontalAlign="Right" />
                </EditFormSettings>
            </MasterTableView>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
            </HeaderContextMenu>
            <PagerStyle Mode="Slider" />
        </telerik:RadGrid>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
        </telerik:RadWindowManager>
    </telerik:RadAjaxPanel>
    <div style="clear: both; height: 2em;">
    </div>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel2" runat="server" />
    <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server">
        <telerik:RadGrid ID="RadGrid2" GridLines="None" runat="server" AllowAutomaticDeletes="True"
            Height="480px" AllowSorting="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
            AllowPaging="True" AllowFilteringByColumn="True" AutoGenerateColumns="False" CellSpacing="0"
            OnNeedDataSource="RadGrid2_NeedDataSource">
            <ClientSettings>
                <Selecting AllowRowSelect="True" />
                <Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
                <Resizing AllowColumnResize="true" />
            </ClientSettings>
            <ExportSettings ExportOnlyData="True">
            </ExportSettings>
            <ValidationSettings EnableValidation="true" />
            <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="ID_POLI,DECORRENZA,GRUPPO,FASCIA"
                EditMode="Popup" HorizontalAlign="NotSet" Width="100%">
                <CommandItemSettings ShowExportToExcelButton="True" />
                <Columns>
                    <telerik:GridDateTimeColumn DataField="DECORRENZA" HeaderText="Decorrenza" SortExpression="DECORRENZA"
                        UniqueName="DECORRENZA" DataFormatString="{0:dd/MM/yyyy}">
                        <HeaderStyle Width="160px" />
                    </telerik:GridDateTimeColumn>
                </Columns>
                <EditFormSettings>
                    <FormTableItemStyle Wrap="False" />
                    <FormCaptionStyle CssClass="EditFormHeader" />
                    <FormMainTableStyle BackColor="White" CellPadding="3" CellSpacing="0" GridLines="None"
                        Width="100%" />
                    <FormTableStyle BackColor="White" CellPadding="2" CellSpacing="0" Height="110px" />
                    <FormTableAlternatingItemStyle Wrap="False" />
                    <EditColumn ButtonType="ImageButton" CancelText="Cancel edit" UniqueName="EditCommandColumn2">
                    </EditColumn>
                    <FormTableButtonRowStyle CssClass="EditFormButtonRow" HorizontalAlign="Right" />
                </EditFormSettings>
            </MasterTableView>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
            </HeaderContextMenu>
            <PagerStyle Mode="Slider" />
        </telerik:RadGrid>
        <telerik:RadWindowManager ID="RadWindowManager2" runat="server">
        </telerik:RadWindowManager>
    </telerik:RadAjaxPanel>
    <asp:LinqDataSource ContextTypeName="GiasoneDBDataContext" EnableDelete="True" EnableInsert="True"
        EnableUpdate="True" TableName="ARS_POLIZZEs" ID="PolizzeDS" runat="server">
    </asp:LinqDataSource>
    <asp:LinqDataSource ContextTypeName="GiasoneDBDataContext" TableName="ARS_POLIZZEATTIVEs"
        ID="PolizzeAttiveDS" runat="server" OrderBy="DESC_POLATT">
    </asp:LinqDataSource>
    <asp:LinqDataSource ContextTypeName="GiasoneDBDataContext" TableName="ARS_ASSICURATIs"
        ID="AssicuratiDS" runat="server">
    </asp:LinqDataSource>
</asp:Content>

And the CS:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
 
public partial class Archivi_Polizze : System.Web.UI.Page {
    private string gridMessage = null;
 
    protected void Page_Load(object sender, EventArgs e) {
        ((MasterPages_principale) Master).Breadcrumb = new Pair("Archivi", "Polizze");
    }
 
    protected void RadGrid1_DataBound(object sender, EventArgs e) {
        if (!string.IsNullOrEmpty(gridMessage)) {
            //DisplayMessage(gridMessage);
        }
    }
 
    protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e) {
        if (e.Exception != null) {
            e.KeepInEditMode = true;
            e.ExceptionHandled = true;
            SetMessage("Update failed. Reason: " + e.Exception.Message);
        } else {
            SetMessage("Item updated!");
        }
    }
 
    protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e) {
        if (e.Exception != null) {
            e.ExceptionHandled = true;
            SetMessage("Insert failed! Reason: " + e.Exception.Message);
        } else {
            SetMessage("New product is inserted!");
        }
    }
 
    protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e) {
        if (e.Exception != null) {
            e.ExceptionHandled = true;
            SetMessage("Delete failed! Reason: " + e.Exception.Message);
        } else {
            SetMessage("Item deleted!");
        }
    }
 
    private void DisplayMessage(string text) {
        RadGrid1.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));
    }
 
    private void SetMessage(string message) {
        gridMessage = message;
        DisplayMessage(message);
    }
 
    protected void rcbPOLATT_ItemDataBound(object sender, RadComboBoxItemEventArgs e) {
        var x = (ARS_POLIZZEATTIVE) e.Item.DataItem;
        e.Item.Text = (x.ID_POLATT + ": " + x.DESC_POLATT);
    }
 
    protected void rcbASSIC_ItemDataBound(object sender, RadComboBoxItemEventArgs e) {
        var x = (ARS_ASSICURATI) e.Item.DataItem;
        e.Item.Text = (x.ID_ASSIC + ": " + x.ARS_ANAGRAFICI.ANAG);
    }
 
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) {
        RadGrid2.Rebind();
    }
 
    protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) {
        var ds = new LinqDataSource();
        ds.ContextTypeName = "GiasoneDBDataContext";
        ds.EnableInsert = true;
        ds.TableName = "ARS_POLIZZETASSIs";
 
        var idobj = RadGrid1.SelectedValue;
 
        if (idobj == null) {
            RadGrid2.Visible = false;
        } else {
            ds.Where = "ID_POLI == " + idobj;
            RadGrid2.Visible = true;
        }
 
        RadGrid2.DataSource = ds;
        RadGrid2.MasterTableView.DataSource = ds;
    }
}
0
Iana Tsolova
Telerik team
answered on 28 Sep 2011, 11:53 AM
Hi Luciano,

Please remove the RadAjaxPanels and see if it makes any difference.

Kind regards,
Iana Tsolova
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
0
Luciano Vernaschi
Top achievements
Rank 1
answered on 28 Sep 2011, 01:46 PM
I removed the RadAjaxPanels and nothing changed. Then I removed ajax completely and the issue is still there. Here's the new aspx:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/principale.master"
    AutoEventWireup="true" CodeFile="Polizze.aspx.cs" Inherits="Archivi_Polizze" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
        .rgEditForm
        {
            width: auto !important;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True"
        Height="480px" AllowSorting="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
        AllowPaging="True" DataSourceID="PolizzeDS" OnItemUpdated="RadGrid1_ItemUpdated"
        AllowFilteringByColumn="True" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted"
        OnDataBound="RadGrid1_DataBound" AutoGenerateColumns="False" CellSpacing="0" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
        <ClientSettings EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="True" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
            <Resizing AllowColumnResize="true" />
        </ClientSettings>
        <ExportSettings ExportOnlyData="True">
        </ExportSettings>
        <ValidationSettings EnableValidation="true" />
        <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="ID_POLI" DataSourceID="PolizzeDS"
            EditMode="Popup" HorizontalAlign="NotSet" Width="100%">
            <CommandItemSettings ShowExportToExcelButton="True" />
            <Columns>
                <telerik:GridBoundColumn DataField="ID_POLI" DataType="System.Int32" HeaderText="Codice"
                    SortExpression="ID_POLI" UniqueName="ID_POLI" ReadOnly="true">
                    <HeaderStyle Width="120px" />
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ID_ASSIC" HeaderText="Assicurato" SortExpression="ID_ASSIC"
                    UniqueName="ID_ASSIC" ReadOnly="true">
                    <HeaderStyle Width="120px" />
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn DataField="ID_ASSIC" HeaderText="Anagrafica" UniqueName="ANAGRAFICA"
                    AllowFiltering="false">
                    <HeaderStyle Width="185px" />
                    <ItemTemplate>
                        <asp:Label runat="server" Text='<%# Eval("ARS_ASSICURATI.ARS_ANAGRAFICI.ANAG") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="rcbASSIC" runat="server" DataSourceID="AssicuratiDS" DataValueField="ID_ASSIC"
                            OnItemDataBound="rcbASSIC_ItemDataBound" SelectedValue='<%#Bind("ID_ASSIC") %>'>
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="ID_POLATT" HeaderText="Polizza Attiva" SortExpression="ID_POLATT"
                    UniqueName="ID_POLATT">
                    <HeaderStyle Width="160px" />
                    <ItemTemplate>
                        <asp:Label runat="server" Text='<%# Eval("ID_POLATT") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="rcbPOLATT" runat="server" DataSourceID="PolizzeAttiveDS"
                            DataValueField="ID_POLATT" OnItemDataBound="rcbPOLATT_ItemDataBound" SelectedValue='<%#Bind("ID_POLATT") %>'>
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="ID_POLATT" HeaderText="Area" UniqueName="POLATT_AREA"
                    AllowFiltering="false">
                    <HeaderStyle Width="160px" />
                    <ItemTemplate>
                        <asp:Label runat="server" Text='<%# Eval("ARS_POLIZZEATTIVE.AREA") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="ID_POLATT" HeaderText="Paese" UniqueName="POLATT_PAESE"
                    AllowFiltering="false">
                    <HeaderStyle Width="160px" />
                    <ItemTemplate>
                        <asp:Label runat="server" Text='<%# Eval("ARS_POLIZZEATTIVE.PAESE") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="DATAAPERTURA" HeaderText="Data Apertura" SortExpression="DATAAPERTURA"
                    UniqueName="DATAAPERTURA">
                    <HeaderStyle Width="160px" />
                    <ItemTemplate>
                        <asp:Label runat="server" Text='<%# Eval("DATAAPERTURA", "{0:d}") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadDatePicker ID="rdpDATAAPERTURA" runat="server" DateInput-CssClass="fldRequired"
                            DbSelectedDate='<%# Bind("DATAAPERTURA") %>'>
                        </telerik:RadDatePicker>
                        <asp:RequiredFieldValidator ControlToValidate="rdpDATAAPERTURA" ErrorMessage="*"
                            runat="server" Display="Dynamic" />
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridDateTimeColumn DataField="DATAESTINZIONE" HeaderText="Data Estinzione"
                    SortExpression="DATAESTINZIONE" UniqueName="DATAESTINZIONE" DataFormatString="{0:dd/MM/yyyy}"
                    ReadOnly="true">
                    <HeaderStyle Width="160px" />
                </telerik:GridDateTimeColumn>
                <telerik:GridDateTimeColumn DataField="DATABLOCCO" HeaderText="Data Blocco" SortExpression="DATABLOCCO"
                    UniqueName="DATABLOCCO" DataFormatString="{0:dd/MM/yyyy}" ReadOnly="true">
                    <HeaderStyle Width="160px" />
                </telerik:GridDateTimeColumn>
                <telerik:GridBoundColumn DataField="MOTIVO" HeaderText="Motivo" SortExpression="MOTIVO"
                    UniqueName="MOTIVO">
                    <HeaderStyle Width="130px" />
                </telerik:GridBoundColumn>
            </Columns>
            <EditFormSettings>
                <FormTableItemStyle Wrap="False" />
                <FormCaptionStyle CssClass="EditFormHeader" />
                <FormMainTableStyle BackColor="White" CellPadding="3" CellSpacing="0" GridLines="None"
                    Width="100%" />
                <FormTableStyle BackColor="White" CellPadding="2" CellSpacing="0" Height="110px" />
                <FormTableAlternatingItemStyle Wrap="False" />
                <EditColumn ButtonType="ImageButton" CancelText="Cancel edit" UniqueName="EditCommandColumn1">
                </EditColumn>
                <FormTableButtonRowStyle CssClass="EditFormButtonRow" HorizontalAlign="Right" />
            </EditFormSettings>
        </MasterTableView>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
        </HeaderContextMenu>
        <PagerStyle Mode="Slider" />
    </telerik:RadGrid>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    </telerik:RadWindowManager>
    <div style="clear: both; height: 2em;">
    </div>
    <telerik:RadGrid ID="RadGrid2" GridLines="None" runat="server" AllowAutomaticDeletes="True"
        Height="480px" AllowSorting="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
        AllowPaging="True" AllowFilteringByColumn="True" AutoGenerateColumns="False" CellSpacing="0"
        OnNeedDataSource="RadGrid2_NeedDataSource">
        <ClientSettings>
            <Selecting AllowRowSelect="True" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
            <Resizing AllowColumnResize="true" />
        </ClientSettings>
        <ExportSettings ExportOnlyData="True">
        </ExportSettings>
        <ValidationSettings EnableValidation="true" />
        <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="ID_POLI,DECORRENZA,GRUPPO,FASCIA"
            EditMode="Popup" HorizontalAlign="NotSet" Width="100%">
            <CommandItemSettings ShowExportToExcelButton="True" />
            <Columns>
                <telerik:GridDateTimeColumn DataField="DECORRENZA" HeaderText="Decorrenza" SortExpression="DECORRENZA"
                    UniqueName="DECORRENZA" DataFormatString="{0:dd/MM/yyyy}">
                    <HeaderStyle Width="160px" />
                </telerik:GridDateTimeColumn>
            </Columns>
            <EditFormSettings>
                <FormTableItemStyle Wrap="False" />
                <FormCaptionStyle CssClass="EditFormHeader" />
                <FormMainTableStyle BackColor="White" CellPadding="3" CellSpacing="0" GridLines="None"
                    Width="100%" />
                <FormTableStyle BackColor="White" CellPadding="2" CellSpacing="0" Height="110px" />
                <FormTableAlternatingItemStyle Wrap="False" />
                <EditColumn ButtonType="ImageButton" CancelText="Cancel edit" UniqueName="EditCommandColumn2">
                </EditColumn>
                <FormTableButtonRowStyle CssClass="EditFormButtonRow" HorizontalAlign="Right" />
            </EditFormSettings>
        </MasterTableView>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
        </HeaderContextMenu>
        <PagerStyle Mode="Slider" />
    </telerik:RadGrid>
    <telerik:RadWindowManager ID="RadWindowManager2" runat="server">
    </telerik:RadWindowManager>
    <asp:LinqDataSource ContextTypeName="GiasoneDBDataContext" EnableDelete="True" EnableInsert="True"
        EnableUpdate="True" TableName="ARS_POLIZZEs" ID="PolizzeDS" runat="server">
    </asp:LinqDataSource>
    <asp:LinqDataSource ContextTypeName="GiasoneDBDataContext" TableName="ARS_POLIZZEATTIVEs"
        ID="PolizzeAttiveDS" runat="server" OrderBy="DESC_POLATT">
    </asp:LinqDataSource>
    <asp:LinqDataSource ContextTypeName="GiasoneDBDataContext" TableName="ARS_ASSICURATIs"
        ID="AssicuratiDS" runat="server">
    </asp:LinqDataSource>
</asp:Content>
0
Iana Tsolova
Telerik team
answered on 30 Sep 2011, 10:44 AM
Hi Luciano,

I am not sure what is the reason for this without being able to debug the project. However I would suggest that in the RadGrid2_NeedDataSource event you bind the grid not to a LinqDataSource but directly using the DataContext. For instance as it is done here.
Your handler might look as the below:
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    GiasoneDBDataContext context = new GiasoneDBDataContext();
    var idobj = RadGrid1.SelectedValue;
    RadGrid2.DataSource = context.ARS_POLIZZETASSIs.Where(a => a.ID_POLI == idobj);
}
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) {
    var idobj = RadGrid1.SelectedValue;
    if (idobj == null) {
        RadGrid2.Visible = false;
    } else {
        RadGrid2.Visible = true;
        RadGrid2.Rebind();
    }
}

Check it out and let me know if this helps.

Best wishes,
Iana Tsolova
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
0
Luciano Vernaschi
Top achievements
Rank 1
answered on 05 Oct 2011, 01:28 PM
Hi, I decided to use a fixed datasource declared in aspx, and to filter the results instead of changing the WHERE clause. I do not consider this a solution since I don't know if I will be able to do the same in future pages, but I needed to proceed in some way.
Tags
Grid
Asked by
Luciano Vernaschi
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Luciano Vernaschi
Top achievements
Rank 1
Share this question
or