0

我实现了第一个解决方案: 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”。

4

1 回答 1

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"。过滤器将与过滤器功能“包含”一起使用,但没关系。

于 2013-03-06T13:58:54.527 回答