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

Custom filter problem

6 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Najid Hanif
Top achievements
Rank 2
Najid Hanif asked on 24 Aug 2011, 07:47 PM
In My grid I have a filter that uses a template with a dropdown. Everything works except when the dropdown is selected , the grid is filtered but the filter dropdown item that was selected is not selected anymore, the 1st item in the list is. How can I keep the item selected in the dropdown list?

Thanks

<FilterTemplate>
  <telerik:RadComboBox runat="server" ID="FilterCombo" DataSourceID="StatusList" UniqueName="StatusFilterCombo"
                       DataValueField="StatusID" DataTextField="Status" AutoPostBack="True"
                       OnSelectedIndexChanged="FilterCombo_SelectedIndexChanged">
  </telerik:RadComboBox>
</FilterTemplate>

6 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 25 Aug 2011, 09:13 AM
Hi Najid,

You can use the approach utilized for the first grid on this demo (specifying SelectedValue for the combobox filters with binding expression) to retain the selection in the comboboxes.

Best regards,
Sebastian
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Najid Hanif
Top achievements
Rank 2
answered on 25 Aug 2011, 02:02 PM
hmm this looked promising but it did not change anything for me. Any other ideas? Here is the code for my entire column:

Thanks

<telerik:GridTemplateColumn DataField="StatusID" FilterControlAltText="Filter TemplateColumn column"
    HeaderText="Status" UniqueName="Status">
 
<FilterTemplate>
  <telerik:RadComboBox runat="server" ID="FilterComboStatus" DataSourceID="StatusList" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Status").CurrentFilterValue %>'
                       DataValueField="StatusID" DataTextField="Status" AutoPostBack="True"
                       OnSelectedIndexChanged="FilterCombo_SelectedIndexChanged">
  </telerik:RadComboBox>
</FilterTemplate>
 
    <EditItemTemplate>
        <telerik:RadComboBox ID="RadComboBox_StatusList" runat="server"
            AutoPostBack="true" DataSourceID="StatusList" DataTextField="Status"
            DataValueField="StatusID"
            OnSelectedIndexChanged="FilterCombo_SelectedIndexChanged"
            SelectedValue='<%#Bind("StatusID") %>'>
        </telerik:RadComboBox>
    </EditItemTemplate>
    <ItemTemplate>
         <%#DataBinder.Eval(Container.DataItem, "Status")%>
    </ItemTemplate>
    <ItemStyle Width="240px" />
</telerik:GridTemplateColumn>
0
Sebastian
Telerik team
answered on 25 Aug 2011, 03:54 PM
Hi Najid,

Does changing the DataValueField property of the combobox filter to Status (instead of StatusID) as well as the DataField property of the template column to Status makes a difference?

Note that you may also consider an alternative solution using your own column which derives from a GridTemplateColumn as demonstrated here (see the definition for the last column in the grid).

Best regards,
Sebastian
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Najid Hanif
Top achievements
Rank 2
answered on 25 Aug 2011, 05:13 PM
No that does not help either. The alternative solution seems unnecessary and more complex then what I would want to do. The SelectedValue property seems like the best route to go. Also note that I am using SelectedValue for the same Column with the EditItemTemplate Column and that works OK.

0
Accepted
Sebastian
Telerik team
answered on 26 Aug 2011, 09:58 AM
Hi Najid,

After I reviewed once again your code, I noticed that you perform postback when an item in the combobox filter is selected (set AutoPostBack = true for the dropdown). Can this be the reason why the combobox selection is reset, as the grid is rebound when filtering operation is triggered?

You can try the approach with client call to the filter method of the grid API as presented in the first live example I linked to compare the results. Also you can debug the value of the CurrentFilterValue property of the Status column to see whether it is set as expected (intercepting the ItemCommand event when e.CommandName is RadGrid.FilterCommandName).

Regards,
Sebastian
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Najid Hanif
Top achievements
Rank 2
answered on 26 Aug 2011, 02:26 PM
When  AutoPostBack = false then  OnSelectedIndexChanged is never fired. This fixes the dropdown from resetting but does not help what I am trying to do. 

I changed my code for ClientSide events like the example you linked to and it now works. I don't know why the Sever side stuff does not work though. Oh well I'll just go with it as it is now, hell at least its working :)

Thanks for the help.
Tags
Grid
Asked by
Najid Hanif
Top achievements
Rank 2
Answers by
Sebastian
Telerik team
Najid Hanif
Top achievements
Rank 2
Share this question
or