How to set a selecting parameter for an ObjectDataSource

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">
            <SelectParameters>
                <asp:Parameter Name="action" ConvertEmptyStringToNull="true" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>

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!
Scarlett72Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
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)?
0
Kyle AbrahamsSenior .Net DeveloperCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scarlett72Author Commented:
Thanks Kyle, apologize for the delay responding got pulled away on another project, took some time for me to get back to this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.