[英]Telerik grid don't show correct item when using custom datasource
我在Telerik網格組件上遇到了一個奇怪的問題...我在談論Webform RadGrid。 我正在做一些評估,現在我正在嘗試使用自己的業務邏輯和數據層來填充網格(FYI,在后台使用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
的方法就像一個魅力。 我沒有實現任何其他RadGrid的事件處理程序,而是在NeedDataSource事件中進行所有操作。 太糟糕了,盡管我為rg.DataSource
和rg.VirtualItemCount
都rg.DataSource
了正確的值,但是在我的網格中我看到的項目卻更少了。 示例:給定一個過濾器,我提取了69個項目,給定每頁10個項目作為網格設置,我在第一頁中僅獲得5個項目,在下一頁中沒有任何項目(分頁器工作正確,我擁有正確的頁面數)。 一個更多的信息。 如果我在NeedDataSource
事件處理程序中添加此行代碼
rg.MasterTableView.FilterExpression = "";
我得到了正確的首頁,但是顯然,刪除過濾器,下一個分頁或排序之類的后續操作將導致過濾器條件的丟失。 有什么線索嗎?
在Telerik的文檔中,我唯一能找到的就是您可能需要處理ItemCommand
事件或其他事件,並重置過濾器。
http://www.telerik.com/help/aspnet-ajax/grid-custom-option-for-filtering.html
這是事件列表,可能會為您提供更多有關在何處攔截並重新應用過濾器的說明
http://www.telerik.com/help/aspnet-ajax/grid-getting-familiar-with-server-side-api.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.