Visual Basic > Using Forums Forums > Off-Topic Posts (Do Not Post Here) > passing an object as a parameter in ObjectDataSource
Ask a questionAsk a question
 

Questionpassing an object as a parameter in ObjectDataSource

  • Tuesday, November 03, 2009 2:56 PMtrager Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a ObjectDataSource on a page which I am using to populated a GridView.  The SelectMethod of the ObjectDataSource accepts a single parameter of TypeclsPerformSearchCriteria.

    The problem I am having is that I have effectively hacked the ObjectDataSource to get it to behave properly and I was wondering if there was perhaps a more elegant way to achieve what I'm after.

    The aspx script:

            <asp:ObjectDataSource ID="PerformSearchDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
    
                SelectMethod="PerformSearchTo_OnlyResultsData" TypeName="CurrentAccountsWebServiceCalls">
    
                <SelectParameters>
    
                    <asp:ControlParameter ControlID="txtPageNo" Name="p_PageNo" DefaultValue="0" Type="Int32" />
    
                    <asp:ControlParameter ControlID="ddlOrderByOption" Name="p_OrderByOption" DefaultValue="1"
    
                        Type="Int32" />
    
                    <asp:ControlParameter ControlID="elbAccountType" PropertyName="EnumeratorValue" Name="p_AccountType"
    
                        DefaultValue="1" />
    
                    <asp:ControlParameter ControlID="txtResultsPerPage" Name="p_ResultsPerPage" DefaultValue="10"
    
                        Type="Int32" />
    
                    <asp:ControlParameter ControlID="chkPackagedAccountOnlyTick" Name="p_chkPackagedAccountOnlyTick"
    
                        Type="Int32" />
    
                    <asp:ControlParameter ControlID="ddlOrderByOption" Name="p_BestBuyOption" Type="Int32" />
    
                </SelectParameters>
    
            </asp:ObjectDataSource>
    
    
    And that seems to required to pick up changes on the controls but then I effectively scrap the values in the code behind:
    Protected Sub PerformSearchDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles PerformSearchDataSource.Selecting
    
            Dim SearchCriteria As CurrentAccountsWebService.clsPerformSearchCriteria
    
    
    
            Try
    
                SearchCriteria = New CurrentAccountsWebService.clsPerformSearchCriteria
    
    
    
                SearchCriteria.PageNo = CInt(txtPageNo.Text)
    
                SearchCriteria.OrderByOption = CType(Me.ddlOrderByOption.SelectedValue, CurrentAccountsWebService.OrderByOption)
    
                SearchCriteria.AccountType = CType(Me.elbAccountType.EnumeratorValue, CurrentAccountsWebService.AccountTypes)
    
                SearchCriteria.ResultsPerPage = CInt(txtResultsPerPage.Text)
    
                SearchCriteria.PackagedAccountOnlyTick = CInt(chkPackagedAccountOnlyTick.Checked)
    
                SearchCriteria.BestBuyOption = CType(ddlBestBuyOption.SelectedValue, CurrentAccountsWebService.BestBuyOption)
    
    
    
                e.InputParameters.Clear()
    
    
    
                e.InputParameters("p_Criteria") = SearchCriteria
    
    
    
            Catch ex As Exception
    
                Throw
    
            End Try
    
        End Sub
    
    
    As I said this code does what I need it to, only it feels a tad "Hacky" if anyone suggest a more elegant solution I'd be greatfull.

    Regards

    Paul

All Replies