RadGrid for ASP.NET

Filtering By ListTextField for GridDropDownColumn Send comments on this topic.
Filtering > How to > Filtering By ListTextField for GridDropDownColumn

Glossary Item Box

The built-in GridDropDownColumn will be filtered by its ListValueField when the default filtering feature of the control is used. Filtering by ListTextField is not attainable in the present version of Telerik RadGrid. The tricky part if that the filtering mechanism of Telerik RadGrid relies on the DataField of the filtered column and for GridDropDownColumn this attribute points to the mapping field in the dropdown source (more info you can find here).

We will consider the possibility to enhance the grid object model in order to allow the option to filter GridDropDownColumn by ListTextField. However, the logic is quite tricky and requires additional research (if achievable at all).

You current options are:

  • use hidden GridBoundColumn (with Display = false) instead of GridDropDownColumn and filter by that column hooking the ItemCommand event:

    ASPX/ASCX Copy Code
    <rad:GridDropDownColumn
      
    UniqueName="CategoryddColumn"
      
    ListTextField="CategoryName"
      
    HeaderText="Category name"
      
    ListValueField="CategoryID"
      
    DataField="CategoryID"
      
    DataSourceID="dataSourceCategories">
    </rad:GridDropDownColumn>

    <
    rad:GridBoundColumn DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName"
     
    UniqueName="CategoryName" Display="false">
    </
    rad:GridBoundColumn>
    C# Copy Code
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
           
    if (e.CommandName == RadGrid.FilterCommandName)
           {
               Pair command=(Pair) e.CommandArgument;
               
    if (command.Second.ToString() == "CategoryddColumn")
               {
                   e.Canceled = true;
                   GridFilteringItem filter = (GridFilteringItem)e.Item;
                   ((filter[
    "CategoryName"].Controls[0]) as TextBox).Text = ((filter["CategoryddColumn"].Controls[0]) as TextBox).Text;
                   command.Second=
    "CategoryName";
                   filter.FireCommandEvent(
    "Filter", new Pair(command.First, "CategoryName"));
               }
           }
    }
    VB.NET Copy Code
    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
     If e.CommandName = RadGrid.FilterCommandName Then

       Dim command As Pair = CType(e.CommandArgument, Pair)

       If command.Second.ToString = "CategoryddColumn" Then

         e.Canceled = True
         Dim filter As GridFilteringItem = CType(e.Item, GridFilteringItem)

         CType(filter("CategoryName").Controls(0), TextBox).Text = CType(filter("CategoryddColumn").Controls(0)), TextBox).Text
         command.Second = "CategoryName"
         filter.FireCommandEvent("Filter", New Pair(command.First, "CategoryName"))
       End If
     End If
    End Sub
  • switch the GridDropDownColumn with GridTemplateColumn (with MS DropDownList in its EditItemTemplate) and enable filtering for the template column as presented here.
  • disable the filtering for the GridDropDownColumn only by setting AllowFiltering = false

    ASPX/ASCX Copy Code
    <rad:GridDropDownColumn UniqueName="CategoryddColumn" DataSourceID="dataSourceCategories" ListTextField="CategoryName"
    FilterListOptions="VaryByDataType" ListValueField="CategoryID" DataField="CategoryID" HeaderText="Category name"
    AllowFiltering="False" />