Hcabnettek
Hcabnettek

Reputation: 12938

ObjectDataSource DataObjectTypeName Help. Pass object as parameter

I have a partial class (the main class is a LinqToSql generated class)

   <DataObject(True)> _
Partial Public Class MBI_Contract

    <DataObjectMethod(DataObjectMethodType.Select, True)> _
   Public Shared Function GetCancelableContracts(ByVal dealer As Dealer) As List(Of MBI_Contract)
        Return Utilities.GetCancelableContractsForDealer(dealer)
    End Function
End Class

Here is the method it's calling

Public Function GetCancelableContractsForDealer(ByVal dealer As Dealer) As List(Of MBI_Contract)
        Dim db As TestDataContext = TestDataContext.Create()
        Return (From mbi As MBI_Contract In db.MBI_Contracts _
                                 Where mbi.MBI_DealerNumber = dealer.DealerNumber _
                                 AndAlso mbi.MBI_PaidFor = True _
                                 AndAlso mbi.MBI_Deleted = False).ToList()
    End Function

I want to use the ObjectDataSource to drive a DropDownList.

  <asp:ObjectDataSource ID="contractOds" runat="server" 
         TypeName="MBI_Contract"
         SelectMethod="GetCancelableContracts" 
         DataObjectTypeName="Dealer">
    </asp:ObjectDataSource>

My aspx page has a Dealer property that is set in a BasePage. My question is how can I pass this property(object) to the ObjectDataSource, so it can be evaluated in my select method. Does anyone know how I can do this? Or am I totally doing this the wrong way?

Thanks for any Advice, Cheers, ~ck in San Diego

Upvotes: 1

Views: 1257

Answers (1)

Hcabnettek
Hcabnettek

Reputation: 12938

Protected Sub contractOds_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles contractOds.Selecting
    e.InputParameters.Insert(0, "dealer", Dealer)

End Sub

This seems to work.

Upvotes: 1

Related Questions