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

DJPB
  • 5,429
  • 8
  • 30
  • 44

3 Answers3

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.

Barry
  • 2,053
  • 3
  • 17
  • 28
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

Community
  • 1
  • 1
George
  • 7,864
  • 5
  • 29
  • 25
  • This method works for me as well. I described it in my answer to this question: http://stackoverflow.com/questions/831208/databind-and-postback/3015512#3015512 – PeterFromCologne Jun 11 '10 at 21:23
0

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

Wil
  • 2,328
  • 2
  • 20
  • 27