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

No results when filtering a grid with a RadComboBox in the FilterTemplate

3 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Irene
Top achievements
Rank 1
Irene asked on 09 Apr 2013, 02:00 PM
Hello,

I'm using a grid in which I'm implementing custom filtering as shown in the documentation and in the online demos, but I'm having some difficulties in making it work properly.

My grid is defined as follows (to try and make it clearer, I'm only copying the impacted column):
<telerik:RadGrid ID="grdBusinessRoles" runat="server" AllowMultiRowSelection="false"
AllowFilteringByColumn="true" ShowFooter="false" AllowSorting="True" AutoGenerateColumns="False"
AllowPaging="true">
<MasterTableView AutoGenerateColumns="false" EditMode="InPlace" TableLayout="Auto"
CommandItemDisplay="Top" DataKeyNames="BusinessRoleId2,BusinessRoleId" PageSize="15">
<CommandItemTemplate>
<asp:LinkButton runat="server" ID="btnClear" Text="Clear Filters" CommandName="ClearFilters" />
</CommandItemTemplate>
<Columns>
<telerik:GridBoundColumn UniqueName="colStream" DataField="StreamName" HeaderText="Stream"
SortExpression="StreamName" ReadOnly="true">
<FilterTemplate>
<telerik:RadComboBox ID="rcbStreams" DataTextField="Value" DataValueField="Value"
AppendDataBoundItems="true" AutoPostBack="false" SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("colStream").CurrentFilterValue %>'
runat="server" OnClientSelectedIndexChanged="SelectedIndexChanged">
<Items>
<telerik:RadComboBoxItem />
</Items>
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function SelectedIndexChanged(sender, args) {
var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");
tableView.filter("colStream", args.get_item().get_value(), "EqualTo");
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
</telerik:GridBoundColumn>
</Columns>
<NoRecordsTemplate>
<asp:Label runat="server" ID="lblNoRecords" Text="No Business Roles found."></asp:Label>
</NoRecordsTemplate>
<PagerStyle PageSizeControlType="RadComboBox" />
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<ClientSettings EnableRowHoverStyle="true">
<Selecting AllowRowSelect="true" />
</ClientSettings>
</telerik:RadGrid>

This grid is contained in a user control, which is contained in another user control, as follows (ucBusinessRoles is the user control containing the grid):
<!-- Select Business Roles -->
<telerik:RadWindow runat="server" ID="wdwBusinessRoles" Modal="true" Width="820px"
   Height="500px" Behaviors="Close" CssClass="RadWindow_Pram">
   <ContentTemplate>
      <telerik:RadAjaxPanel ID="pnlBusinessRoles" runat="server">
      <pram:ucBusinessRoles ID="ucSelectBusinessRole" runat="server" TypeOfList="AssignRoleVariants"
         TypeOfSelection="SingleSelection" AllowNavigation="False" AllowNewBusinessRole="False" />
      </telerik:RadAjaxPanel>
      <telerik:RadButton ID="btnAddRolesToList" runat="server" Text="Select Role" CssClass="RadButton_Pram submit" />
   </ContentTemplate>
</telerik:RadWindow>

The RadComboBox used for filtering is bound to a dictionary, as follows:
Protected Sub grdBusinessRoles_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) _
   Handles grdBusinessRoles.ItemCreated
 
   If TypeOf (e.Item) Is GridFilteringItem Then
      Dim filterItem As GridFilteringItem = CType(e.Item, GridFilteringItem)
      Dim combo As RadComboBox = CType(filterItem("colStream").FindControl("RadComboBoxClientName"), RadComboBox)
 
      combo.DataSource = Streams ' This is a Dictionary(Of Decimal, String)
      combo.DataValueField = "value"
      combo.DataTextField = "value"
   End If
 
End Sub

And the whole grid is bound in the NeedDataSource event.

The grid is displayed correctly and the drop-down list is populated correctly, but if I select a in the drop-down list to filter by it, then the grid refreshes and all the records are "filtered" (so it doesn't matter which value I select for filtering: I will always get no results, even if the list contains valid items), so the filtered grid will always be empty (see attachments).

I've tried several approaches and followed the tutorials and demos, but I couldn't get this working.

What am I doing wrong?

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 12 Apr 2013, 08:48 AM
Hi Irene,

I would suggest you to review the online demo below which presents the proper approach for filtering RadGrid with RadCombobox in the FilterTemplate:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx

I hope this helps.

Regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Irene
Top achievements
Rank 1
answered on 15 Apr 2013, 08:09 AM
Hello Maria,

thanks for your reply.

Before posting, I have already checked the demos, looked for other examples on the forums and searched for posts that might describe an issue similar to mine, but, as you can expect, I've had no luck.

I don't know if this is related to the particular configuration I have (binding through the NeedDataSource event, nested user controls, presence of the RadWindow control, etc...). This is getting critical for us, and we really need to get this working, but I don't know what else I could try. There must be something wrong in my implementation, but I couldn't detect where it is, so far.

Can you please give me more support on this?
0
Elliott
Top achievements
Rank 2
answered on 15 Apr 2013, 07:25 PM
it all looks right to me - although I filtered on a combobox outside the grid - and manipulated the FilterExpression in code
are you sure the value of the contents of the Dictionary object is "value"?
if I was stuck I would put some test code to iterate through that dictionary object to build the combo box or its data source manually and try that
Tags
Grid
Asked by
Irene
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Irene
Top achievements
Rank 1
Elliott
Top achievements
Rank 2
Share this question
or