[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How to set a selecting parameter for an ObjectDataSource

Posted on 2014-08-06
Medium Priority
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
ID: 40245973
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 41

Accepted Solution

Kyle Abrahams earned 2000 total points
ID: 40246290
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

ID: 40255707
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

872 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