Question

I have a Telerik radgrid view and read date from DB with linq technique.
Now when I click on 2th or 3th... page I need (force) to click again on load button.
This is my code:

<telerik:RadGrid ID="GV_GRWDAS" runat="server"  AllowPaging="true" AllowCustomPaging="false" AllowSorting="True" CellSpacing="0" GridLines="None" AutoGenerateColumns="False" Font-Names="tahoma" Font-Size="12px">
    <SortingSettings SortToolTip="برای مرتب سازی اینجا کلیک کنید" SortedAscToolTip="مرتب سازی صعودی" SortedDescToolTip="مرتب سازی نزولی" EnableSkinSortStyles="true" />
    <AlternatingItemStyle Font-Names="tahoma" Font-Size="12px" HorizontalAlign="Center" VerticalAlign="Middle" />
<Columns>
    <telerik:GridBoundColumn DataField="DateFa" FilterControlAltText="Filter DateFa column" HeaderText="تاریخ" UniqueName="DateFa">
    </telerik:GridBoundColumn>
    <telerik:GridNumericColumn DataField="Resturant" FilterControlAltText="Filter DateFa column" HeaderText="رستوران (ريال)" UniqueName="Resturant" DataFormatString="{0:##,#0}">
    </telerik:GridNumericColumn>  

This is click event:

protected void btnPrint_Click(object sender, ImageClickEventArgs e)
{
    try
    {
        string msg = "";
        if (Isvalid(ref msg))
        {
            var dbobj = new DriversDB.DriversModelDataContext();
            //var list = dbobj.vw_ReportWithdrawAccountSummations.Where(rwas => rwas.DateFa
            var q =
                (from d in dbobj.usp_vw_ReportWithdrawAccountSummation_GetReportWithdrawAccountSummation_ForPrint(dateFrom, dateTo)
                select d);//.ToList <usp_vw_ReportWithdrawAccountSummation_GetReportWithdrawAccountSummation_ForPrintResult>();

            GV_GRWDAS.DataSource = q;
            GV_GRWDAS.DataBind();
            Thread.Sleep(500);
            //LoadData();
        }
        else
        {
            MessageBox.Show(msg);
        }

    }
    catch (Exception)
    {   
    }

How do I fix this problem?

Était-ce utile?

La solution

If I remember correctly telerik does not render nor adds all the data to viewstate. So you will need to reset the DataSource every time the code behind is called in this case paging. You can avoid the effort in identifying each action by setting the datasource on onneeddatasource event.

This is mentioned on Telerik Grid common Mistakes: http://www.telerik.com/help/aspnet-ajax/grid-most-common-mistakes.html

  1. Missing or not using NeedDataSource event The NeedDataSource event helps developers easily control scenarios like paging, sorting, and grouping, with Telerik RadGrid . Using these types of PostBack events, which RadGrid fires, can lead to a change in the Items collections of each GridTableView in a Telerik RadGrid .
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top