Asp.net's ObjectDataSource data bind event
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
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.
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
You can create the objectdatasource in the code behind and do the bind onclick.
精彩评论