2

So, I have a GridView with an ObjectDataSource, and I want to programmatically set one of the SelectParameters of the ObjectDataSource.

I tried (during both Page_Load and DropdownList__SelectedIndexChanged)

objectDataSource.SelectParameters["my_parameter"].DefaultValue = "my_value";
objectDataSource.DataBind();

but it didn't work. What would you suggest?

2 Answers 2

2

Trap the onselecting event on the datasource.

protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
    e.InputParameters["month"] = DateTime.Now.Month;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Nevermind, I solved it myself.

In Page_Load:

objectDataSource.Selecting += new ObjectDataSourceSelectingEventHandler(objectDataSource_Selecting);

Then write the handler method:

void objectDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
    int four = 2 + 2;
    e.InputParameters["my_parameter"] = four;
}

Then make sure to databind the GridView somewhere

protected void dropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
    gridView.DataBind();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.