Object DataSource With Paramaters

Prefix the Business Logic Layer method that accepts parameters with the following. otherwise the object DataSource will not identify this method that accepts parameters:

 [DataObjectMethod(DataObjectMethodType.Select)]

Example:

    [DataObjectMethod(DataObjectMethodType.Select)]
    public static DataTable GetInvestorFilingDataTable(InvestorDataFeedType feedType)
    {

        List<InvestorFilingData> entireList = new List<InvestorFilingData>();
    
        entireList = DAL.GetInvestorFilingData(feedType);

        DataTable datatable = ListToDataTable(entireList);

        return datatable;

    }        

Then to pass params to this method within your datasource specify SelectParameter’s:

<asp:ObjectDataSource ID="DataSourceFilingsDT" runat="server" SelectMethod="GetInvestorFilingDataTable"
    TypeName="BLL" OnSelected="DataSourceFilingsDT_Selected" 
    OldValuesParameterFormatString="original_{0}" 
    onselecting="DataSourceFilingsDT_Selecting">
    <SelectParameters>
        <asp:Parameter Name="feedType" Type="Object" />
    </SelectParameters>
</asp:ObjectDataSource>

To pass values to the method within the DataSource:

 protected void DataSourceFilingsDT_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        // Change the Parameter of feedType within GetInvestorFilingDataTable
        e.InputParameters["feedType"] = DataToDisplay;
    }

More info here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s