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

Share ObjectDataSource with multiple combos

3 Answers 45 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 17 Mar 2011, 10:54 PM
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

3 Answers, 1 is accepted

Sort by
0
Jon
Top achievements
Rank 1
answered on 17 Mar 2011, 11:34 PM
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
0
Dimitar Terziev
Telerik team
answered on 23 Mar 2011, 09:32 AM
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
0
Jon
Top achievements
Rank 1
answered on 23 Mar 2011, 09:51 AM
Thanks for the confirmation Dimitar.
Tags
ComboBox
Asked by
Jon
Top achievements
Rank 1
Answers by
Jon
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or