How to set a selecting parameter for an ObjectDataSource

Scarlett72
Scarlett72 used Ask the Experts™
on
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!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2008

Commented:
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)?
Senior .Net Developer
Commented:
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

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial