首页 文章

使用自定义数据源时,Telerik网格不显示正确的项目

提问于
浏览
0

我对Telerik网格组件有一个奇怪的问题......我在谈论webform RadGrid . 我正在做一些评估,现在我正在尝试使用我自己的业务逻辑和数据层来提供网格(仅供参考,在场景后面使用NHibernate) . 我设法让分页,过滤和订购工作得很好...唯一的事情是我在过滤时看到的,不是我的业务层提取的...... mmmm . 我清楚了 . 这是代码aspx

<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" GridLines="None" AllowFilteringByColumn="True"
    AllowPaging="True" AllowSorting="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
    AllowAutomaticUpdates="True" OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateColumns="False" AllowCustomPaging="True"
    EnableLinqExpressions="True"  >
    <MasterTableView DataKeyNames="CountryID" EditMode="Batch" >
        <BatchEditingSettings EditType="Cell" />
        <Columns>
            <telerik:GridBoundColumn DataField="CountryID" FilterControlAltText="Filter CountryID column"
                HeaderText="ID" ReadOnly="True" SortExpression="CountryID" UniqueName="CountryID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Description" FilterControlAltText="Filter Name column"
                HeaderText="Name" SortExpression="Description" UniqueName="Description">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="IsUE" DataType="System.Byte" FilterControlAltText="Filter IsUE column"
                HeaderText="Is UE" SortExpression="IsUE" UniqueName="IsUE">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="VatApply" DataType="System.Byte" FilterControlAltText="Filter VatApply column"
                HeaderText="Vat Apply" SortExpression="VatApply" UniqueName="VatApply">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="IsActive" DataType="System.Byte" FilterControlAltText="Filter Active column"
                HeaderText="Active" SortExpression="IsActive" UniqueName="IsActive">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Continent" FilterControlAltText="Filter Continent column"
                HeaderText="Continent" SortExpression="Continent" UniqueName="Continent">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FlgDazi" DataType="System.Byte" FilterControlAltText="Filter FlgDazi column"
                HeaderText="FlgDazi" SortExpression="FlgDazi" UniqueName="FlgDazi">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="PCHost" FilterControlAltText="Filter PCHost column"
                HeaderText="PCHost" SortExpression="PCHost" UniqueName="PCHost" Visible="False">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Status" FilterControlAltText="Filter Status column"
                HeaderText="Status" SortExpression="Status" UniqueName="Status" Visible="False">
            </telerik:GridBoundColumn>                
            <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="50px" ButtonType="ImageButton"
                CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
            </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

而且,在我背后的代码中

protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        var csa =
            new CountryServiceAdv(new SqlServerDataContext(ConnStr, GeoData.Context.GeoDataContext.GetAssemblies()), logAppenders);

        var rg = sender as RadGrid;

        int startRowIndex = rg.CurrentPageIndex * rg.PageSize;
        int maximumRows = rg.PageSize;
        var countries = csa.GetCountries(startRowIndex, maximumRows, GetSortExpression(rg), rg.MasterTableView.FilterExpression);

        rg.DataSource = countries;
        rg.VirtualItemCount = csa.Count(rg.MasterTableView.FilterExpression);
    }

2 csa 's method work like a charm. I don' t实现了任何其他RadGrid的事件处理程序,我在NeedDataSource事件中做了所有事情 . 太糟糕了,尽管我对 rg.DataSourcerg.VirtualItemCount 都有正确的值,但在我的网格中,我看到的项目更少 . 示例:给出一个过滤器,我提取了69个项目,每页给出10个项目作为网格设置,我在第一页中只得到5个项目而在下一个页面中没有项目(分页器工作正常,我有正确的页面数量) ) . 还有一个信息 . 如果我在 NeedDataSource 事件处理程序中添加这行代码

rg.MasterTableView.FilterExpression = "";

我得到了第一页,但很明显,删除过滤器,下一步操作,如分页或排序,将导致过滤条件的丢失 . 有线索吗?

1 回答

相关问题