How to set a selecting parameter for an ObjectDataSource

Posted on 2014-08-06
Last Modified: 2014-08-12
Hi I want to pass a parameter to a dataset in a typed dataset .xsd tableadapter.  So when a user clicks on the button named 'Add' they will see the data associated with 'Add' and when they click on the button named 'Remove' they will see the data associated with 'Remove'  

 <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="RapidFire.RFTableAdapters.USP_RD_UPSELL_CALCTableAdapter" OnSelecting="ObjectDataSource2_Selecting">
                <asp:Parameter Name="action" ConvertEmptyStringToNull="true" Type="String" />

Open in new window

So I think I'm supposed to create a 'Selecting' event and do something like this:

protected void ObjectDataSource2_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
            e.InputParameters[""] = "Add";

Open in new window

I'm not really sure how to apply logic so when a user presses the add or remove button they are going to get the appropriate data ... any point in the right direction would really be appreciated!
Question by:Scarlett72
    LVL 96

    Expert Comment

    by:Bob Learned
    It looks like you are heading in the right direction, but InputParameters doesn't have a name associated with it, and are you looking to determine which option was selected (Add or Remove)?
    LVL 39

    Accepted Solution

    create a global variable (string action):

    string action = "";
    protected void page_load(...)

    Open in new window

    In your add click:
    btnAdd_Click(object sender, EventArgs e)
       action = "add";
       theList.DataBind();  //whatever is binding to the ODS

    Open in new window

    then finally for your selecting:
    protected void ObjectDataSource2_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
                e.InputParameters["action"] = action;

    Open in new window

    Note that a global variable is NOT remembered between postbacks.  You would need to use the session for that, but a global variable can be used for one call to the code behind.

    Author Closing Comment

    Thanks Kyle, apologize for the delay responding got pulled away on another project, took some time for me to get back to this.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now