Share ObjectDataSource with multiple combos

4 posts, 0 answers
  1. Jon
    Jon avatar
    813 posts
    Member since:
    Oct 2008

    Posted 17 Mar 2011 Link to this post

    Hi Everyone,

    OK I have a page with several lists of companies.  I want the first list to show gas service providers, the next electricity providers etc.  My objectdatasource can filter the type of company that it returns and I'd like to use the single objectdatasource for all combo boxes.  I thought OK I'll determine which combo is requesting the data in the Selecting event and supply the relevant CompanyTypeID as a param there.  Doh, I can't seem to work out which combo is requesting the list.

    1) Is there something that I have missed re getting the calling object?
    2) Short of having multiple different objectdatasources for each company type is there a work around?

    This is inside a Formview to make it a little more complex.

    Best Regards,

    Jon
  2. Jon
    Jon avatar
    813 posts
    Member since:
    Oct 2008

    Posted 17 Mar 2011 Link to this post

    One work around that I have found is to call the OnDataBinding for each of the combos in the form, then depending on the ID assign a value to the CompanyTypeID - as shown below.  If anyone knows a better approach I'd be very grateful.

    Regards,

    Jon

    Private _companyTypeID As Integer = Nothing
     
            Protected Sub uxCompanyDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles uxCompanyDataSource.Selecting
                e.InputParameters("ConnectionString") = getAmonetConnectionString()
                e.InputParameters("CompanyTypeID") = _companyTypeID
            End Sub
     
            Protected Sub CompanyCombo_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
                Select Case DirectCast(sender, RadComboBox).ID
                    Case "uxOwnerCompanyID" : _companyTypeID = 14
                    Case "uxLettingAgentID" : _companyTypeID = 13
                    Case "uxSolicitorID" : _companyTypeID = 12
                    Case "uxGasServiceProviderID" : _companyTypeID = 5
                    Case "uxElectServiceProviderID" : _companyTypeID = 6
                    Case "uxWaterServiceProviderID" : _companyTypeID = 7
                    Case "uxTVSatServiceProviderID" : _companyTypeID = 10
                    Case "uxTelecomsServiceProviderID" : _companyTypeID = 8
                    Case "uxBroadbandServiceProviderID" : _companyTypeID = 9
                    Case "uxCouncilTaxServiceProviderID" : _companyTypeID = 11
                End Select
            End Sub
  3. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 23 Mar 2011 Link to this post

    Hi Jon,

    What you have found as a workaround seems to be the most appropriate approach in order to determine, which ComboBox is firing the event and thus, bind it with the corresponding data.

    Greetings,
    Dimitar Terziev
    the Telerik team
  4. Jon
    Jon avatar
    813 posts
    Member since:
    Oct 2008

    Posted 23 Mar 2011 Link to this post

    Thanks for the confirmation Dimitar.
Back to Top