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

ComboBox with TextBox Filtering

9 Answers 210 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Oscar
Top achievements
Rank 1
Oscar asked on 30 Nov 2010, 06:23 PM

When I run the page without the Rebind() method call in my PreRender() method I get the desired filtering behavior, for the most part. We want the ComboBoxes to have a cascading data feature. When I set AppendDataBoundItems=”false” this does the trick but the user can no longer set the ComboBox to “ALL”. I put in a button to clear all the filters and that isn’t too bad. The problem I am running into now is when I have the ComboBoxes set and type in a first or last name that is invalid the page does nothing but says there is an error. I went to http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultvb.aspx and when you set the country to Argentina then set the filter for Is Promoted to yes the page loads http://demos.telerik.com/ErrorPageResources/error.aspx?aspxerrorpath=/aspnet-ajax/grid/examples/programming/filtertemplate/defaultvb.aspx this error. I thought that it was just a random connection but apparently your filters have the same issue that I am trying to overcome. I am guessing that you guys are aware of this issue, are there any suggestions on something that could be done? Or am I limited to trying to make the possibility of this happening as small as possible?
I also would like to have the ComboBoxes show all values that are on the same level as the current selection. For an example if it was States and Cities, and I had selected California for the state and Los Angeles for the City, I would like to click on the city combobox and have it display all cities in the state of California. Where would be a place to start looking for that possibility?

I thought maybe it would help to include a little more information from a prior question that this issue pertains to:


======================================================================================================
 



 

Posted on Nov 23, 2010 (permalink)

I wrote something that is very similar to this Demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplatedeclarativerelations/defaultvb.aspx

The difference is my radgrid has sorting features enabled. After running a sort to narrow down the list, the rows no longer expand. It triggers the event, and seems to do everything else properly but does not expand the rows so that specific data is available to the user.

I would appreciate any feedback and will offer my code if it's necessary. I thought that it would be something to do with the code behind but after working on this for a day and a half I am almost certain it's some setting I missed in the aspx page. I'm still researching this issue as I work but I could really use a hint or three.

Thanks,
Oscar

Edit your post Reply

  • Oscar avatar

    Posted on Nov 23, 2010 (permalink)

    After doing some more work on this I am going to post a few snippets of where I think the error could be at this point. I have tried using a DetailTable with a GridTableView inside the radgrid. My original iteration was with the nestedtemplateview, (I prefer this version it looked nicer and was exactly what we wanted for the application I am building). I am having the same exact issue with both of these attempts. The rows expand and show the view, but once a filter has been applied to the main RadGrid it does not expand the row. 

    <MasterTableView AutoGenerateColumns="False"
        DataSourceID="SqlDataSource1"
        DataKeyNames="USER_ID"
        AllowMultiColumnSorting="true"
        Width="100%">

    <telerik:RadGrid ID="RadGrid1" runat="server"
        AllowFilteringByColumn="True"
        AllowPaging="True"
        AllowSorting="True"
        DataSourceID="SqlDataSource1"
        GridLines="None"
        Skin="Outlook"
        PageSize="100"
        EnableLinqExpressions="False"
        ShowGroupPanel="True"
        ShowStatusBar="True"
        AutoGenerateColumns="false">
        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"
            AllowDragToGroup="True">
            <Selecting AllowRowSelect="True" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>


        Protected Sub RadGrid1_PreRender(ByVal o As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender
     
            If Not RadGrid1.MasterTableView.FilterExpression Is String.Empty Then
     
                FilterSetter()
            End If
        End Sub
     
        Private Sub FilterSetter()
     
            sqlLocationFilter.SelectCommand = "SELECT DISTINCT [DBOL] FROM [DBO]" & " WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [Location]"
            sqlDepartmentFilter.SelectCommand = "SELECT DISTINCT [DOBD] FROM [DBO]" & " WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [DBOD]"
            sqlOfficeFilter.SelectCommand = "SELECT DISTINCT [DBOO] FROM [DBO]" & " WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [DBOO]"
     
            RadGrid1.MasterTableView.Rebind()
        End Sub
     
        Protected Sub ResetFiltersButton_OnClick(ByVal o As Object, ByVal e As EventArgs)
     
            RadGrid1.MasterTableView.FilterExpression = String.Empty
     
            For Each column As GridColumn In RadGrid1.MasterTableView.RenderColumns
     
                If TypeOf column Is GridBoundColumn Then
     
                    Dim boundColumn As GridBoundColumn = TryCast(column, GridBoundColumn)
                    boundColumn.CurrentFilterValue = String.Empty
                End If
            Next
     
            RadGrid1.Rebind()
        End Sub
     
        Protected Sub RadGrid1_ItemCommand(ByVal o As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
     
            If e.CommandName = Telerik.Web.UI.RadGrid.ExpandCollapseCommandName Then
     
                Dim item As GridItem
     
                For Each item In e.Item.OwnerTableView.Items
     
                    TestExpandEvent.Visible = True
                    If item.Expanded And item IsNot e.Item Then
     
                        item.Expanded = False
                    End If
                Next
            End If
        End Sub
    End Class

    I hope this is enough to help,

    Oscar

    Edit your post Reply

  • Oscar avatar

    Posted on Nov 24, 2010 (permalink)

    I've found the cause of my problem but how to fix the issue is escaping me. I can't quite figure out what is stopping it from extending the rows.

    When the FilterSetter function runs as it is the rows don't expand.
    Protected Sub RadGrid1_PreRender(ByVal o As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender
        If Not RadGrid1.MasterTableView.FilterExpression Is String.Empty Then
            FilterSetter()
        End If
    End Sub
    Private Sub FilterSetter()
        SqlLocationFilter.SelectCommand = "SELECT DISTINCT [Location] FROM [View_PhoneList_Debra] " & "WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [Location]"
        SqlDepartmentFilter.SelectCommand = "SELECT DISTINCT [Department] FROM [View_PhoneList_Debra] " & "WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [Department]"
        RadGrid1.MasterTableView.Rebind()
    End Sub

    When I take the RadGrid1.MasterTableView.Rebind() line out of the code it still gives me the ability to expand the rows. But my combobox filters aren't getting set properly anymore.

    I had thought that this could help a bit, I did some testing and the event does fire and run through this function properly so I know it gets through here. I've still not found a way to solve this problem yet:

    Protected Sub RadGrid1_ItemCommand(ByVal o As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If e.CommandName = Telerik.Web.UI.RadGrid.ExpandCollapseCommandName Then
            Dim item As GridItem
            For Each item In e.Item.OwnerTableView.Items
                If item.Expanded And item IsNot e.Item Then
                    item.Expanded = False
                End If
            Next
        End If
    End Sub

    Edit your post Reply

  • Answer Telerik Admin admin's avatar

    Posted on Nov 26, 2010 (permalink)

    Hello Oscar,

    The PreRender event is breaking your scenario. In the FilterSetter() method (called if the FilterExpression is not empty - meaning if there is a filter applied) calls RadGrid.MasterTableView.Rebind().  Rebinding is an operation that recreates all grid items in their default state. This means that, after rebinding, your items are collapsed. So what happens:

    1. You filter the grid. Now with a non-empty FilterExpression, RadGrid will rebind on every PreRender.
    2. You try to expand an item. The ItemCommand event is fired in RadGrid and the item is internally expanded, the detail table / nested view is databound.
    3. In PreRender, RadGrid is rebound, as you have applied a filter that causes FilterSetter(). At this point, your expanded item is gone, because the grid items are recreated.

    Hope this clarifies the scenario.

    Veli
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

    Unmark answer Reply

  • Oscar avatar

    Posted 1 day ago (permalink)

    When I run the page without the Rebind() method call in my PreRender() method I get the desired filtering behavior, for the most part. We want the ComboBoxes to have a cascading data feature. When I set AppendDataBoundItems=”false” this does the trick but the user can no longer set the ComboBox to “ALL”. I put in a button to clear all the filters and that isn’t too bad. The problem I am running into now is when I have the ComboBoxes set and type in a first or last name that is invalid the page does nothing but says there is an error. I went to http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultvb.aspx and when you set the country to Argentina then set the filter for Is Promoted to yes the page loads http://demos.telerik.com/ErrorPageResources/error.aspx?aspxerrorpath=/aspnet-ajax/grid/examples/programming/filtertemplate/defaultvb.aspx this error. I thought that it was just a random connection but apparently your filters have the same issue that I am trying to overcome. I am guessing that you guys are aware of this issue, are there any suggestions on something that could be done? Or am I limited to trying to make the possibility of this happening as small as possible?

     

    I also would like to have the ComboBoxes show all values that are on the same level as the current selection. For an example if it was States and Cities, and I had selected California for the state and Los Angeles for the City, I would like to click on the city combobox and have it display all cities in the state of California. Where would be a place to start looking for that possibility?

    Edit your post Reply

  • 9 Answers, 1 is accepted

    Sort by
    0
    Oscar
    Top achievements
    Rank 1
    answered on 02 Dec 2010, 04:48 PM
    Should this be in a different thread? I've been trying to figure out where the problem is occuring so that I can either try to catch it or prevent the issue from being a problem but for the life of me I can't quite figure out when it's really becoming an issue. I have "EnableLinqExpressions="False"" in my RadGrid but it's still doing as described as well as the demo you have on your page. So if you guys are as lost as I am maybe we can collaberate a bit and figure this out.

    Thanks,
    Oscar
    0
    Oscar
    Top achievements
    Rank 1
    answered on 20 Dec 2010, 05:41 PM
    Still haven't been able to figure this issue out yet. In the meantime I have just created 2 pages, one that has the option to filter by textboxes, and another page that has the dropdown filtering. In an ideal situation having both of these on one page would be best for the type of application I am building.

    Any suggestions or help would be greatly appreciated,

    Oscar

    0
    Veli
    Telerik team
    answered on 23 Dec 2010, 01:24 PM
    Hello Oscar,

    We are also able to reproduce what you are reporting. We were able to find the reason why is that happening. It is because the last combo (ImportedFilter) is not databound. It always has the options [Yes], [No] and [NoFilter]. However, after filtering Argentina in the countries combo, there are no items with Yes value for the Imported boolean field. At that point, when you select Yes from the combo, the filtered items do not match the previous applied filter (Argentina). This is causing the exception.

    If the ImportedFilter combo was databound, it would have the Yes option after choosing Argentina from the countries. Thus, you would not get an exception due to invalid state of the data and the filter expressions. We will update the demo example with a fix for that scenario. Effectively, the ImportedFilter needs to be databound just like the other combos to the available values after filtering.

    Veli
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
    0
    Oscar
    Top achievements
    Rank 1
    answered on 23 Dec 2010, 05:12 PM
    Where is this error being thrown from. I've spent a good while trying to find where it's coming from so that I can at least let the user know that invalid entry was put into the textbox instead of just sending them to a 404 error page, or having the gridview stare at them as if it's getting ready to do something. I am using a pair of databound combo boxes for filtering and for my other purpose we are using free textboxes for two other filters. The current "Fix" for this issue has been to release two pages, one with the textbox filters and one with the databound comboboxes.

    I wouldn't want to just drop a try/catch statement around the whole radgrid/all filtering if it's not necessary because if there is another issue it will be kind of tough to track down.

    Thanks,

    Oscar
    0
    Veli
    Telerik team
    answered on 03 Jan 2011, 12:13 PM
    RadComboBox is breaking after databinding when you filter, because you pass it a selected value but the combo has no items. Here is the exact scenario:

    1. You filter by Argentina from the countries combo. Result - 3 items. The countries combo binds to 1 item, because only Argentina is returned from its data source after filtering.
    2. You select Yes from the IsPromoted combo. Note that the current grid source (3 items) does not contain an item with true value for the IsPromoted field. At this point the data sources of all combos are further filtered by true for the boolean field.
    3. The countries combo gets 0 items from its data source. Why? Because there are no records with Argentina and true for the IsPromoted field at the same time.

    At point 3, the exception occurs when the countries combo is databinding. Why the exception? Because the grid column tells it to set a SelectedValue of Argentina but the combo has no items!

    To avoid this exception, we simply do not allow the IsPromoted combo to contain values that are not valid for the current filtered set of items. Thus, in the updated scenario, filtering by Argentina removes the Yes option from the last combo. You cannot filter by values that will yield 0 records in the filtered result.

    Veli
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
    0
    Subhashini
    Top achievements
    Rank 1
    answered on 01 Apr 2015, 04:35 PM
    This is the exact situation for me. Could you guide me on how to remove the option from the cascading radcombo box (Point 3
    )?
    I tried combo.item.remove(1) under RadGrid1_ItemDataBound and RadGrid1_ItemDataCreated. I keep getting the ArgumentOutofrangeexception - Selection out of range Parameter name: value error
    0
    Subhashini
    Top achievements
    Rank 1
    answered on 01 Apr 2015, 05:30 PM
    This is the exact situation for me. Could you guide me on how to remove the option from the cascading radcombo box (Point 3
    )?
    I tried combo.item.remove(1) under RadGrid1_ItemDataBound and RadGrid1_ItemDataCreated. I keep getting the ArgumentOutofrangeexception - Selection out of range Parameter name: value error
    0
    Viktor Tachev
    Telerik team
    answered on 06 Apr 2015, 11:01 AM
    Hello Subhashini,

    Note that the SelectCommand for the DataSource controls is modified in the code behind. Thus, after filtering only relevant items are displayed in the remaining RadComboBox controls that are used for filtering. Check out the RefreshCombos() method in the code-behind of the demo.

    http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx


    Regards,
    Viktor Tachev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
    0
    Subhashini
    Top achievements
    Rank 1
    answered on 06 Apr 2015, 05:30 PM

    Thanks Viktor. I am able to disable the irrelevant option in the radcombobox.

    Tags
    Filter
    Asked by
    Oscar
    Top achievements
    Rank 1
    Answers by
    Oscar
    Top achievements
    Rank 1
    Veli
    Telerik team
    Subhashini
    Top achievements
    Rank 1
    Viktor Tachev
    Telerik team
    Share this question
    or