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

Reset Multiple Radcomboboxes as filters in RadGrid

2 Answers 114 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
illumination
Top achievements
Rank 2
illumination asked on 03 Mar 2009, 06:54 PM
I need to know how to reset radcombobox as filter in the radgrid.
                <telerik:GridBoundColumn DataField="Dept" HeaderText="Department" SortExpression="Dept" 
                    UniqueName="Dept" > 
                    <FilterTemplate> 
                    <asp:TextBox runat="server" ID="TextBox1" style="display:none;">  
                    </asp:TextBox> 
                    <telerik:RadComboBox ID="cboRadDept" DataSourceID="DeptSqlDS" DataTextField="Name" DataValueField="Name"   
                        AutoPostBack="True" AppendDataBoundItems="True" Height="100%" Width="170px" 
                        SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("Dept").CurrentFilterValue %>' 
                        runat="server" OnSelectedIndexChanged="cboRadDept_SelectedIndexChanged" Skin="WebBlue" > 
                        <Items> 
                        <telerik:RadComboBoxItem /> 
                        </Items> 
                    </telerik:RadComboBox> 
                    </FilterTemplate> 
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="From" HeaderText="Originator" SortExpression="From"   
                    UniqueName="From">  
                    <FilterTemplate> 
                    <asp:TextBox runat="server" ID="TextBox2" style="display:none;">  
                    </asp:TextBox> 
                    <telerik:RadComboBox ID="cboRadFrom" DataSourceID="FromSqlDS" DataTextField="UserName" DataValueField="UserName"   
                        AutoPostBack="True" AppendDataBoundItems="True"   
                        SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("From").CurrentFilterValue %>' 
                        runat="server" OnSelectedIndexChanged="cboRadFrom_SelectedIndexChanged" Skin="WebBlue">  
                        <Items> 
                        <telerik:RadComboBoxItem /> 
                        </Items> 
                    </telerik:RadComboBox> 
                    </FilterTemplate> 
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Status" HeaderText="Status" SortExpression="Status" UniqueName="Status">  
                    <FilterTemplate> 
                    <asp:TextBox runat="server" ID="TextBox3" style="display:none;">  
                    </asp:TextBox> 
                    <telerik:RadComboBox ID="cboRadStatus" DataSourceID="StatusSqlDS" DataTextField="Status" DataValueField="Status"   
                        AutoPostBack="True" AppendDataBoundItems="True" Height="100%" Width="85px"   
                        SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("Status").CurrentFilterValue %>' 
                        runat="server" OnSelectedIndexChanged="cboRadStatus_SelectedIndexChanged" Skin="WebBlue">  
                        <Items> 
                        <telerik:RadComboBoxItem /> 
                        </Items> 
                    </telerik:RadComboBox> 
                    </FilterTemplate> 
                </telerik:GridBoundColumn> 
 
    Protected Sub cboRadDept_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
        Dim filterItem As GridFilteringItem = DirectCast(RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)  
        TryCast(filterItem("Dept").Controls(1), TextBox).Text = e.Value  
        filterItem.FireCommandEvent("Filter", New Pair("EqualTo", "Dept"))  
    End Sub  
 
    Protected Sub cboRadFrom_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
        Dim filterItem As GridFilteringItem = DirectCast(RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)  
        TryCast(filterItem("From").Controls(1), TextBox).Text = e.Value  
        filterItem.FireCommandEvent("Filter", New Pair("EqualTo", "From"))  
    End Sub  
 
    Protected Sub cboRadStatus_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
        Dim filterItem As GridFilteringItem = DirectCast(RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)  
        TryCast(filterItem("Status").Controls(1), TextBox).Text = e.Value  
        filterItem.FireCommandEvent("Filter", New Pair("Contains", "Status"))  
    End Sub  
 
I am able to use 3 radcomboboxes as filters in the grid. the problem is that when I finished filtering and I have AppendDataBoundItems="True" and using <Items><telerik:RadComboboxItem></Items>, that it will automatically give me 1 empty row. if I click this empty row, it won't go back to selectedvalue. it's like nothing or selectedindex = -1 and then rebind the grid with the rest of the filters. Or is there another way?
Please help.
Thank you.

2 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 06 Mar 2009, 11:21 AM
Hi illumination,

To see how this can be done, review the implementation from the following online demo of RadGrid for ASP.NET AJAX (Q1 2009 Beta):

http://demos.telerik.com/aspnet-ajax-beta/grid/examples/programming/filtertemplate/defaultcs.aspx

The idea is to invoke the filter method from the client-side API of the grid with the value from the filter control/ filter function passed as an argument. Feel free to modify/extend the approach to conform to your project schema.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
illumination
Top achievements
Rank 2
answered on 06 Mar 2009, 03:26 PM
Sebastian,
Thank you for the reply.
I have figured it out. I am currently using the 1314 version of Q3 so I am not using beta yet.
This is my solution:
add cboRadDept_Prerender on cboRadDept, cboRadFrom_Prerender on cboRadFrom, cboRadStatus_Prerender on cboRadStatus.

    Protected Sub cboRadDept_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
        Dim filterItem As GridFilteringItem = DirectCast(RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)  
        If (e.Value.ToString()) = "" Then  
            ViewState("cboRadDeptValue") = e.Value  
            TryCast(filterItem("Dept").Controls(1), TextBox).Text = e.Value  
            filterItem.FireCommandEvent("Filter", New Pair("NoFilter", "Dept"))  
        Else  
            ViewState("cboRadDeptValue") = e.Value  
            TryCast(filterItem("Dept").Controls(1), TextBox).Text = e.Value  
            filterItem.FireCommandEvent("Filter", New Pair("EqualTo", "Dept"))  
        End If  
    End Sub  
 
    Protected Sub cboRadFrom_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
        Dim filterItem As GridFilteringItem = DirectCast(RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)  
        If (e.Value.ToString()) = "" Then  
            ViewState("cboRadFromValue") = e.Value  
            TryCast(filterItem("From").Controls(1), TextBox).Text = e.Value  
            filterItem.FireCommandEvent("Filter", New Pair("NoFilter", "From"))  
        Else  
            ViewState("cboRadFromValue") = e.Value  
            TryCast(filterItem("From").Controls(1), TextBox).Text = e.Value  
            filterItem.FireCommandEvent("Filter", New Pair("EqualTo", "From"))  
        End If  
    End Sub  
 
    Protected Sub cboRadStatus_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
        Dim filterItem As GridFilteringItem = DirectCast(RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)  
        If (e.Value.ToString()) = "" Then  
            ViewState("cboRadStatusValue") = e.Value  
            TryCast(filterItem("Status").Controls(1), TextBox).Text = e.Value  
            filterItem.FireCommandEvent("Filter", New Pair("NoFilter", "Status"))  
        Else  
            ViewState("cboRadStatusValue") = e.Value  
            TryCast(filterItem("Status").Controls(1), TextBox).Text = e.Value  
            filterItem.FireCommandEvent("Filter", New Pair("Contains", "Status"))  
        End If  
    End Sub  
 
    Protected Sub cboRadDept_PreRender(ByVal sender As Object, ByVal e As EventArgs)  
        If ViewState("cboRadDeptValue") <> Nothing Then  
            TryCast(sender, RadComboBox).SelectedValue = ViewState("cboRadDeptValue").ToString()  
        ElseIf ViewState("cboRadDeptValue") = "" Then  
            TryCast(sender, RadComboBox).SelectedValue = "" 
        End If  
    End Sub  
 
    Protected Sub cboRadFrom_PreRender(ByVal sender As Object, ByVal e As EventArgs)  
        If ViewState("cboRadFromValue") <> Nothing Then  
            TryCast(sender, RadComboBox).SelectedValue = ViewState("cboRadOriginatorValue").ToString()  
        ElseIf ViewState("cboRadFromValue") = "" Then  
            TryCast(sender, RadComboBox).SelectedValue = "" 
        End If  
    End Sub  
 
    Protected Sub cboRadStatus_PreRender(ByVal sender As Object, ByVal e As EventArgs)  
        If ViewState("cboRadStatusValue") <> Nothing Then  
            TryCast(sender, RadComboBox).SelectedValue = ViewState("cboRadStatusValue").ToString()  
        ElseIf ViewState("cboRadStatusValue") = "" Then  
            TryCast(sender, RadComboBox).SelectedValue = "" 
        End If  
    End Sub 
Thanks for link though, I will need it when I move to the new Q1 2009.
Tags
ComboBox
Asked by
illumination
Top achievements
Rank 2
Answers by
Sebastian
Telerik team
illumination
Top achievements
Rank 2
Share this question
or