0

I'm Working on an Asp.net/C# application. I want to bind a list of objects to a grid view. I've been looking a while to the ObjectDataSource control and it loads data to my datagrid as soon as my page loads. Can I change this behaviour? For example, how can I set DataBinding only when a button on my page gets clicked?

tks

3 Answers 3

1

You can hook into the ObjectDataSource's Selecting event and cancel any selects that don't match the criteria you're looking for. I do this all the time based on values in other controls.

Look at the e.Cancel property for that event.

Sign up to request clarification or add additional context in comments.

Comments

1

Do not set the datasource in markup and simply do it in the code-behind on the OnClick event of the button.

Programatically, you can specify the object to bind to as shown in the answer to this question...

ASP.NET 2.0: Specifying an instance of an object for an ObjectDataSource

1 Comment

This method works for me as well. I described it in my answer to this question: stackoverflow.com/questions/831208/databind-and-postback/…
0

You can create the objectdatasource in the code behind and do the bind onclick.

1 Comment

Bad idea, because you might loose the benefits that you get by using the ODS.

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.