【问题标题】:telerik gridview paging not workingTelerik gridview 分页不起作用
【发布时间】:2013-12-28 11:53:59
【问题描述】:

我有一个 Telerik radgrid 视图并使用 linq 技术从 DB 读取日期。
现在,当我单击第 2 或第 3 页面时,我需要(强制)再次单击加载按钮。
这是我的代码:

<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>  

这是点击事件:

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)
    {   
    }

我该如何解决这个问题?

【问题讨论】:

  • 删除AllowCustomPaging="false" 怎么样?
  • 我删除了它,但没有任何改变。我把这个 radgrid 放在一个更新面板 asp.net 标记中

标签: asp.net linq gridview telerik telerik-grid


【解决方案1】:

如果我没记错的话,telerik 不会渲染也不会将所有数据添加到视图状态。因此,在这种情况下,每次调用后面的代码时,您都需要重置 DataSource。您可以通过在 onneeddatasource 事件上设置数据源来避免识别每个操作的工作。

Telerik Grid common Mistakes 中提到了这一点: http://www.telerik.com/help/aspnet-ajax/grid-most-common-mistakes.html

  1. 缺少或未使用 NeedDataSource 事件 NeedDataSource 事件可帮助开发人员使用 Telerik RadGrid 轻松控制分页、排序和分组等场景。使用 RadGrid 触发的这些类型的 PostBack 事件可能会导致 Telerik RadGrid 中每个 GridTableView 的 Items 集合发生变化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多