我有一个radgrid,它从网站上的两个搜索框之一返回文本的结果。我们希望能够按列过滤网格中的搜索结果。我添加了AllowFilteringByColumn =' true'在radgrid参数中,但是当您在radgrid过滤器文本框中输入文本时,没有任何刷新。
我已经研究了服务器端和客户端过滤之间的区别,但如果我不必,我真的不想再次调用数据库。由于返回了数据,因此创建asp sqldatasource花费的时间太长。是否有一种简单的方法来过滤结果集而不进行另一次调用? NeedDataSource调用getDataGrid,它从搜索中提取文本,查询数据库并返回。我们的网格列是在预渲染中创建的。
感谢。
这是我的代码:
<div id="grid">
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceId="SqlDataSource1" EnableLinqExpressions="false" AutoGenerateColumns="true" Skin="WebBlue" AllowPaging="true" AllowSorting="true" CellSpacing="0" GridLines="Both" OnNeedDataSource="NeedDataSource" PageSize="50" OnPreRender="RadGrid1_PreRender" AllowMultiRowSelection="false" AllowFilteringByColumn="true">
<PagerStyle Mode="NextPrevAndNumeric" />
<ItemStyle CssClass="UsePointer" />
<MasterTableView AllowFilteringByColumn="true" CommandItemDisplay="bottom">
<SortExpressions><telerik:GridSortExpression FieldName="field1" SortOrder="Ascending" /></SortExpressions>
<Columns>
<telerik:GridTemplateColumn HeaderStyle-CssClass="commandHeader" HeaderStyle-Width="30px" Exportable="false" UniqueName="checkCol">
<HeaderTemplate>
<asp:CheckBox ID="checkAll" runat="server" onclick="CheckAll(this)" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="cboxSelect" runat="server" onclick="unCheckHeader(this); enableMassUpdate()" OnCheckedChanged="GridCheckBoxChanged" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<CommandItemSettings ShowExportToExcelButton="false" ShowAddNewRecordButton="false" ShowRefreshButton="false"/>
</MasterTableView>
<ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true" >
<Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
<Selecting AllowRowSelect="true" />
<ClientEvents OnRowSelecting="RowSelecting" OnRowSelected="RowSelected" OnCommand="ClearForm" />
<KeyboardNavigationSettings EnableKeyboardShortcuts="false" AllowSubmitOnEnter="false" AllowActiveRowCycle="false" ></KeyboardNavigationSettings>
</ClientSettings>
</telerik:RadGrid>
</div>
protected void NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
(source as RadGrid).DataSource = getDataGrid("RadGrid1");
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridColumn checkCol = RadGrid1.MasterTableView.GetColumnSafe("field1");
checkCol.OrderIndex = 1;
GridColumn assetDeptCol = RadGrid1.MasterTableView.GetColumn("field2");
assetDeptCol.HeaderStyle.Width = Unit.Pixel(115);
assetDeptCol.HeaderText = "Field2";
assetDeptCol.OrderIndex = 2;
GridColumn assetIDCol = RadGrid1.MasterTableView.GetColumn("field3");
assetIDCol.Display = false;
etc....
RadGrid1.Rebind();
;