Helper
Helper

Reputation: 11

How to pass parameter programmatically in objectdatasource

I want to pass 3 parameters for SelectMethod and 1 parameters for SelectCountMethod of ObjectDataSource.

How can I pass these? And how ObjectDataSource can distinguish which parameters for which methods?

Upvotes: 1

Views: 3954

Answers (2)

user959883
user959883

Reputation:

Instead of using selecting event you can also directly add parameters in your button click or anyother function . It must differentiate on the basis of parameter name . I haven't tested it but it shall work.

ObjectDataSource2.SelectParameters.Clear()
ObjectDataSource2.SelectParameters.Add("Parameter1",ValueOfParameter1);

Upvotes: 1

Jeroen
Jeroen

Reputation: 4023

There are two ways of passing parameters to an ObjectDatasource.

1) Through it's wizard you can bind the parameters to various controls, form fields, querystring, session, etc.

2) In it's Selecting event. Example:

protected void Page_Load(object sender, EventArgs e)
        {
            myObjDs.Selecting += new ObjectDataSourceSelectingEventHandler(myObjDs_Selecting);
        }

void myObjDs_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            e.InputParameters["someparamname"] = "test";
        }

Upvotes: 1

Related Questions