This is a migrated thread and some comments may be shown as answers.

Bug in Solution: Filtering By ListTextField for GridDropDownColumn

14 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason Walters
Top achievements
Rank 1
Jason Walters asked on 03 Feb 2010, 05:53 PM
Hi,

I implemented the first solution outlined in the following example:

http://www.telerik.com/help/aspnet-ajax/grdfilteringbylisttextfieldforgriddropdowncolumn.html

(use a hidden GridBoundColumn (with Display = false). Add an ItemCommand event handler that catches filter commands from GridBoundColumn and substitutes a filter command from the GridDropDownColumn instead)

This works well, however there is a bad side effect.

For a normal column without a need for custom handling, say an integer value, when you type in an integer like "3" and selet a filter, the value of "3" persists visually when the page reloads, and the end user can now tell that the column is filtered by "3".

However, for the columns handled in the RadGrid1_ItemCommand (as outlined in the solution) - after typing in a value and clicking on the filter selection (EqualTo), the value typed in does not persist once the page reloads.  The filter has bee succesfully applied, and the RadGrid now shows a targeted list based upon the filter entered, but the end user has no way of seeing what value the grid is being filtered by.

Have you identified a work around for this?    Thanks.

14 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 09 Feb 2010, 06:39 AM
Hello Jason,

One possible option in this case would be to get a reference to the filter textbox, and set the value there directly. More information on how to get a reference to the textbox can be found in the following article:

http://www.telerik.com/help/aspnet-ajax/grdsettingfiltertextboxdimensions.html

I hope this information helps.

Kind regards,
Yavor
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Tiago
Top achievements
Rank 1
answered on 01 Mar 2013, 04:33 PM
Hi,

I implemented the first solution in:
http://www.telerik.com/help/aspnet-ajax/grid-filtering-by-listtextfield-for-griddropdowncolumn.html

My code is:
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;
}
}

The filter is working only the first time with the filter function "StartsWith" and after it seems to be changing the filter function to "EqualTo".


Thanks
0
Shinu
Top achievements
Rank 2
answered on 02 Mar 2013, 05:57 AM
Hi,

Try setting the DataType to "System.String" as shown below.

ASPX:
<telerik:GridDropDownColumn DataSourceID="SqlDataSource2" DataType="System.String" . . .>

Thanks,
Shinu.
0
Tiago
Top achievements
Rank 1
answered on 04 Mar 2013, 01:13 PM
Hi Shinu,

Setting the DataType to "System.String" almost solved my problem. But now the filter is with another strange behavior, it does not work only the first time.


Thanks
0
Shinu
Top achievements
Rank 2
answered on 05 Mar 2013, 06:21 AM
Hi,

Try setting the DataType as "System.String" for the GridBoundColumn as shown below. Please take a look into the code snippet I tried.

ASPX:
<telerik:GridDropDownColumn UniqueName="CategoryddColumn" ListTextField="EmployeeID"
    HeaderText="Category name" ListValueField="OrderID" DataField="OrderID" DataSourceID="SqlDataSource1"
    CurrentFilterFunction="StartsWith" AllowVirtualScrolling="true" ShowMoreResultsBox="true"
    ItemsPerRequest="10" FilterControlWidth="100%" ShowFilterIcon="false" FooterText=""
    AllowAutomaticLoadOnDemand="false" AutoPostBackOnFilter="true">
</telerik:GridDropDownColumn>
<telerik:GridBoundColumn DataField="EmployeeID"  DataType="System.String"
    UniqueName="EmployeeID" Display="false">
</telerik:GridBoundColumn>

C#:
protected void RadGrid2_ItemCommand(object sender, Telerik.Web.UI.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["EmployeeID"].Controls[0]) as TextBox).Text = ((filter["CategoryddColumn"].Controls[0]) as TextBox).Text;
            command.Second = "EmployeeID";
            filter.FireCommandEvent("Filter", new Pair(command.First, "EmployeeID"));
        }
    }
}
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        GridFilteringItem item = e.Item as GridFilteringItem;
        ((item["CategoryddColumn"].Controls[0]) as TextBox).Text = ((item["EmployeeID"].Controls[0]) as TextBox).Text;
    }
}

Thanks,
Shinu.
0
Tiago
Top achievements
Rank 1
answered on 05 Mar 2013, 05:31 PM
Hi Shinu, 

I implemented my code as shown in your code snippet, setting the DataType as "System.String" for the GridBoundColumn gives me the first behavior I had, the filter is working only the first time with the filter function "StartsWith" and after it seems to be changing the filter function to "EqualTo".


Thanks
0
Shinu
Top achievements
Rank 2
answered on 06 Mar 2013, 05:03 AM
Hi,

Try setting the Filter function in the ItemCommand event as shown below.

C#:
protected void RadGrid2_ItemCommand(object sender, Telerik.Web.UI.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["EmployeeID"].Controls[0]) as TextBox).Text = ((filter["CategoryddColumn"].Controls[0]) as TextBox).Text;
            command.Second = "EmployeeID";
            filter.FireCommandEvent("Filter", new Pair("StartsWith", "EmployeeID"));
        }
    }
}

Thanks,
Shinu.
0
Tiago
Top achievements
Rank 1
answered on 06 Mar 2013, 01:37 PM
Hi Shinu,

Thank you very much! I have solved it.
The problem was in the 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>

The solution was setting the DataType="System.String" for the GridDropDownColumn and removing the CurrentFilterFunction="StartsWith". The filter will work with the filter function "Contains", but it is ok.

Thanks,

Tiago

0
Shinu
Top achievements
Rank 2
answered on 07 Mar 2013, 03:41 AM
Hi Tiago,

For the filter to work with 'StartsWith', you can set the FilterFunction 'StartsWith' in the ItemCommand event as I have shown in the above.

C#:
protected void gridCultos_ItemCommand(object source, GridCommandEventArgs e)
{
 
                . . .
                command.Second = "NM_COMUNIDADE";
                filter.FireCommandEvent("Filter", new Pair("StartsWith", "NM_COMUNIDADE"));
        }
    }
}

Thanks,
Shinu.
0
Anup
Top achievements
Rank 1
answered on 12 Dec 2013, 11:44 AM
Hello All

Having some problem in filtration of ListTextField. Below is my code snippet .

aspx----
<telerik:RadGrid ID="radBuildRouteDetails" DataSourceID="dsBuildRouteDetails" runat="server"
         AutoGenerateColumns="False" AllowAutomaticDeletes="True"
         AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True" AllowPaging="True"
         AllowSorting="true" Width="65%" EnableLinqExpressions="false" GridLines="None"
         AllowFilteringByColumn="true"
         ShowStatusBar="true" oninsertcommand="radBuildRouteDetails_InsertCommand"
         onupdatecommand="radBuildRouteDetails_UpdateCommand"
         OnItemInserted="radBuildRouteDetails_ItemInserted"
         OnItemUpdated="radBuildRouteDetails_ItemUpdated"
         OnItemCommand="radBuildRouteDetails_ItemCommand"
         onitemdatabound="radBuildRouteDetails_ItemDataBound"
         onprerender="radBuildRouteDetails_PreRender">
         <PagerStyle Mode="NumericPages"></PagerStyle>
         <ClientSettings EnableRowHoverStyle="true" AllowExpandCollapse="True">
             <Selecting AllowRowSelect="true" />
         </ClientSettings>
         <SelectedItemStyle CssClass="SelectedItem" />
         <MasterTableView Name="Route" DataSourceID="dsBuildRouteDetails" DataKeyNames="RouteID" ClientDataKeyNames="RouteID"
             AllowMultiColumnSorting="True" CommandItemDisplay="Top" AllowFilteringByColumn="true" HierarchyLoadMode="Client"
             AllowAutomaticInserts="false">
             <CommandItemSettings AddNewRecordText="Add New Task Group" />
             <DetailTables >
                 <telerik:GridTableView Name="ChildRoute" DataSourceID="dsBuildRouteChildDetails" DataKeyNames="rowguid"
                     Width="100%" CommandItemDisplay="Top">
                     <ParentTableRelation>
                         <telerik:GridRelationFields DetailKeyField="RouteID" MasterKeyField="RouteID"></telerik:GridRelationFields>
                     </ParentTableRelation>
                     <CommandItemSettings AddNewRecordText="Add New Sub Locations" />
                     <Columns>
                         <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn1">
                             <HeaderStyle Width="20px"></HeaderStyle>
                             <ItemStyle CssClass="MyImageButton"></ItemStyle>
                         </telerik:GridEditCommandColumn>
                         <telerik:GridBoundColumn DataField="RowGuid" HeaderText="RowGuid" UniqueName="RowGuid"
                             Visible="false" ReadOnly="true">
                         </telerik:GridBoundColumn>
                         <telerik:GridDropDownColumn  UniqueName="SubLocationID" HeaderText="SubLocation" ColumnEditorID="GridDropDownListColumnEditor2"
                             ListTextField="Asset" ListValueField="SubLocationID" DataSourceID="dtSubLocation" AllowFiltering="false"
                             DropDownControlType="RadComboBox" DataField="SubLocationID" HeaderStyle-Width="160px">
                         </telerik:GridDropDownColumn>
                  
                         <telerik:GridButtonColumn ConfirmText="Delete this sub location?" ButtonType="ImageButton"
                             CommandName="Delete" Text="Delete" UniqueName="DeleteColumn2">
                             <HeaderStyle Width="20px"></HeaderStyle>
                             <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
                         </telerik:GridButtonColumn>
                     </Columns>
                 </telerik:GridTableView>
             </DetailTables>
             <Columns>
               <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                     <ItemStyle CssClass="MyImageButton"></ItemStyle>
                 </telerik:GridEditCommandColumn>
                 <telerik:GridBoundColumn DataField="RouteID" HeaderText="Task Group ID" AllowFiltering="true"
                     UniqueName="RouteID" HeaderStyle-Width="150px">
                 </telerik:GridBoundColumn>
              
                 <telerik:GridDropDownColumn UniqueName="SubContractorColumn" ListTextField="Subcontractor"
                     HeaderText="Sub contractor" ListValueField="SubcontractorID" DataField="SubcontractorID"
                     DataSourceID="dsSubContractor" AllowVirtualScrolling="true" ShowMoreResultsBox="true"
                     DataType="System.String" DropDownControlType="RadComboBox" ItemsPerRequest="10"
                     FilterControlWidth="100%" ShowFilterIcon="false" FooterText="" AllowAutomaticLoadOnDemand="false"
                     AutoPostBackOnFilter="true" HeaderStyle-Width="150px">
                 </telerik:GridDropDownColumn>
                 <telerik:GridBoundColumn DataField="Subcontractor" UniqueName="Subcontractor" Display="false">
                 </telerik:GridBoundColumn>
 
                 <telerik:GridButtonColumn ConfirmText="Delete this route?" ButtonType="ImageButton"
                     CommandName="Delete" Text="Delete" UniqueName="DeleteColumn2">
                     <HeaderStyle Width="20px"></HeaderStyle>
                     <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
                 </telerik:GridButtonColumn>
             </Columns>
         </MasterTableView>
     </telerik:RadGrid>
 
      <asp:SqlDataSource ID="dsSubContractor" runat="server" ConnectionString="<%$ ConnectionStrings:ABMAssuredString %>"
         ProviderName="System.Data.SqlClient" SelectCommand="SELECT [SubcontractorID], [Subcontractor] FROM Subcontractor">
     </asp:SqlDataSource>

//Code Behind
      protected void radBuildRouteDetails_ItemDataBound(object sender, GridItemEventArgs e)
      {
          if (e.Item is GridFilteringItem)
          {
              GridFilteringItem item = e.Item as GridFilteringItem;
              ((item["SubContractorColumn"].Controls[0]) as TextBox).Text = ((item["Subcontractor"].Controls[0]) as TextBox).Text;
          }
      }
 
      protected void radBuildRouteDetails_ItemCommand(object sender, GridCommandEventArgs e)
      {
          if (e.CommandName == RadGrid.FilterCommandName)
          {
              Pair command = (Pair)e.CommandArgument;
              if (command.Second.ToString() == "SubContractorColumn")
              {
                  e.Canceled = true;
                  GridFilteringItem filter = (GridFilteringItem)e.Item;
                  ((filter["Subcontractor"].Controls[0]) as TextBox).Text = ((filter["SubContractorColumn"].Controls[0]) as TextBox).Text;
                  command.Second = "Subcontractor";
                  filter.FireCommandEvent("Filter", new Pair(command.First, "Subcontractor"));
              }
          }
           
      }

Any suggestion would be appreciated ..
0
Princy
Top achievements
Rank 2
answered on 06 Jan 2014, 08:57 AM
Hi Anup,

Access the tables using its Name property to identify Master and Detail tables. Please try the following code snippet:

C#:
protected void radBuildRouteDetails_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem && e.Item.OwnerTableView.Name == "Route")
    {
        GridFilteringItem item = e.Item as GridFilteringItem;
        ((item["SubContractorColumn"].Controls[0]) as TextBox).Text = ((item["Subcontractor"].Controls[0]) as TextBox).Text;
    }
}
 
protected void radBuildRouteDetails_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        Pair command = (Pair)e.CommandArgument;
        if (command.Second.ToString() == "SubContractorColumn")
        {
            e.Canceled = true;
            GridFilteringItem filter = (GridFilteringItem)e.Item;
            ((filter["Subcontractor"].Controls[0]) as TextBox).Text = ((filter["SubContractorColumn"].Controls[0]) as TextBox).Text;
            command.Second = "Subcontractor";
            filter.FireCommandEvent("Filter", new Pair(command.First, "Subcontractor"));
        }
    }
}

Thanks,
Princy
0
Pavel
Top achievements
Rank 1
answered on 28 Jan 2014, 08:49 PM
I am hopelessly stuck trying to implement the solution in this treads
I am getting a ParseException: Neither of the types 'String' and 'Int32' converts to the other

Here's my code
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        Pair command = (Pair)e.CommandArgument;
        if (command.Second.ToString() == "StatesDropdown")
        {
            e.Canceled = true;
            GridFilteringItem filter = (GridFilteringItem)e.Item;
            ((filter["StatesDropdown"].Controls[0]) as TextBox).Text = ((filter["StatesNames"].Controls[0]) as TextBox).Text;
            command.Second = "StatesNames";
            filter.FireCommandEvent("Filter", new Pair(command.First, "State"));
        }
    }
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        GridFilteringItem item = e.Item as GridFilteringItem;
        ((item["StatesDropdown"].Controls[0]) as TextBox).Text = ((item["StatesNames"].Controls[0]) as TextBox).Text;
    }
}

<telerik:GridDropDownColumn DataSourceID="odsStates"
                            ListTextField="State"
                            ListValueField="StateId"
                            UniqueName="StatesDropdown"
                            DataField="StatesLkup.StateId"
                            DropDownControlType="RadComboBox"
                            AutoPostBackOnFilter="true"
                            DataType="System.String" />
 
 
<telerik:GridBoundColumn DataField="StatesLkup.StateId"
                         UniqueName="StatesNames"
                         Display="false"
                         ReadOnly="true"
                         DataType="System.String" />
 
    <asp:ObjectDataSource ID="odsStates"
                          TypeName="xxx.Services.GrantDataService"
                          SelectMethod="GetStates"
                          DataObjectTypeName="xxx.Domain.StatesLkup"
                          OnObjectCreating="odsStates_ObjectCreating"
                          runat="server" />
0
Princy
Top achievements
Rank 2
answered on 29 Jan 2014, 05:48 AM
Hi Pavel,

Ensure that the fields specified through the DataField/ListValueField properties are of the same data type and the entries have a precise match, otherwise you will get merely the first item from the list displayed in non-editable mode. This can also happen if you have not configured properly the GridDropDownColumn, e.g. the relations between the fields specified through the DataField/ListValueField properties. Since you have to display the TextField, the BoundColumn should be bound to State.

ASPX:
<telerik:GridBoundColumn DataField="State" UniqueName="StatesNames" Display="false" DataType="System.String" />

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        Pair command = (Pair)e.CommandArgument;
        if (command.Second.ToString() == "StatesDropdown")
        {
            e.Canceled = true;
            GridFilteringItem filter = (GridFilteringItem)e.Item;
            ((filter["StatesNames"].Controls[0]) as TextBox).Text = ((filter["StatesDropdown"].Controls[0]) as TextBox).Text;
            command.Second = "StatesNames";
            filter.FireCommandEvent("Filter", new Pair(command.First, "StatesNames"));
        }
    }
}

Thanks,
Princy
0
Pavel
Top achievements
Rank 1
answered on 29 Jan 2014, 09:04 PM
Thanks for your help, Princy.
Tags
Grid
Asked by
Jason Walters
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Tiago
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Anup
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Pavel
Top achievements
Rank 1
Share this question
or