DataBind and Postback

This is a general question, how does DataBind ask questions ...

I have a simple page with a GridView that is bound (in aspx code) to an ObjectDataSource object.

I can look in the Select () function called by ObjectDataSource to see that it is called on boot and in each column. I have some logic that occurs on mail servers that will affect GridView data, and I want to call GridView.DataBind () later in the message after I made some changes.

Is there a way to prevent automatic recovery that occurs in each column? Does this mean that I cannot use the ObjectDataSource object for this control?

+6
source share
3 answers

You are correct that the fine-grained control you are looking for is impossible and requires code. ASP.NET data source objects are nothing more than a pain in **. You will find that as you use them, you will get situations like this happening over and over.

Some of the problems you will find are:

  • Not strongly typed
  • Inflexible (as you already noted)
  • Wise presentation code

I started accessing data in code and did not look back.

+12
source

I also fought this automatic snap and thought I posted my solution here:

  • remove the "DataSourceID" from the ASPX page when it is not installed, there is no automatic binding
  • set DataSourceID to CodeBehind only when DataBinding is required: myGridView.DataSourceID = "MyDataSource";
  • do not call myGridView.DataBind () explicitly, data binding occurs automatically in PreRender

It's time to figure it out, but now everything works fine.

Context

I use ObjectDatasource because it automatically passes me all swap and sort for a gridview. I use the data layer with Linq2SQL and use its Skip () and Take () methods to load only the amount of data needed to fill one page of the GridView.

Using SelectMethod and SelectCountMethod of an ObjectDataSource

+8
source

Yes. If you need such control when data binding occurs, you need to do this in code.

+2
source

All Articles