ObjectDataSource - how can I bind only if button pressed

1.5k Views Asked by At

I have a button, which when presses populates a grid with data. If I add an ObjectDataSource, and bind the grid to it, it will populate the grid when the page loads. But I need to populate the grid only if the button is pressed, because it is a lengthy opperation. How should I accomplish this

1

There are 1 best solutions below

0
On BEST ANSWER

add an event handler to ObjectDataSource's Selecting event like this:

protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
    if (!IsPostBack)
    {
       e.Cancel = true;
    }
}

and put a button on page, when it was clicked a postback will occur and ObjectDataSource will return data successfully.