我实施了第一个解决方案: Filtering By ListTextField for GridDropDownColumn
我的代码是:
ASPX
<telerik:GridDropDownColumn DataSourceID="SqlDataSource2" ListTextField="NM_COMUNIDADE" ListValueField="ID_COMUNIDADE" UniqueName="NM_COMUNIDADE_COLUNA" SortExpression="NM_COMUNIDADE" HeaderText="Comunidade"
DataField="ID_COMUNIDADE"DropDownControlType="RadComboBox" FooterText="" AllowAutomaticLoadOnDemand="false" AutoPostBackOnFilter="true" CurrentFilterFunction="StartsWith" AllowVirtualScrolling="true"
ShowMoreResultsBox="true" ItemsPerRequest="10" FilterControlWidth="100%" ShowFilterIcon="false" ColumnEditorID="NM_COMUNIDADE_EDITOR">
</telerik:GridDropDownColumn>
<telerik:GridBoundColumn DataField="NM_COMUNIDADE" HeaderText="NM_COMUNIDADE" SortExpression="NM_COMUNIDADE" UniqueName="NM_COMUNIDADE" Display="false" ReadOnly="true"></telerik:GridBoundColumn>
C#
protected void gridCultos_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName)
{
Pair command = (Pair)e.CommandArgument;
if (command.Second.ToString() == "NM_COMUNIDADE_COLUNA")
{
e.Canceled = true;
GridFilteringItem filter = (GridFilteringItem)e.Item;
((filter["NM_COMUNIDADE"].Controls[0]) as TextBox).Text = ((filter["NM_COMUNIDADE_COLUNA"].Controls[0]) as TextBox).Text;
command.Second = "NM_COMUNIDADE";
filter.FireCommandEvent("Filter", new Pair(command.First, "NM_COMUNIDADE"));
}
}
}
protected void gridCultos_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridFilteringItem)
{
GridFilteringItem item = e.Item as GridFilteringItem;
((item["NM_COMUNIDADE_COLUNA"].Controls[0]) as TextBox).Text = ((item["NM_COMUNIDADE"].Controls[0]) as TextBox).Text;
}
}
过滤器仅在第一次使用过滤器功能“StartsWith”时,并且似乎将过滤器功能更改为“EqualTo”。
答案 0 :(得分:1)
问题出在ASPX中:
<telerik:GridDropDownColumn UniqueName="CategoryddColumn" ListTextField="EmployeeID"
HeaderText="Category name" ListValueField="OrderID" DataField="OrderID" DataSourceID="SqlDataSource1"
AllowVirtualScrolling="true" ShowMoreResultsBox="true" DataType="System.String"
ItemsPerRequest="10" FilterControlWidth="100%" ShowFilterIcon="false" FooterText=""
AllowAutomaticLoadOnDemand="false" AutoPostBackOnFilter="true">
</telerik:GridDropDownColumn>
<telerik:GridBoundColumn DataField="EmployeeID" UniqueName="EmployeeID" Display="false">
</telerik:GridBoundColumn>
解决方案是为GridDropDownColumn设置DataType =“System.String”并删除CurrentFilterFunction =“StartsWith”。过滤器将使用过滤器功能“包含”,但没关系。