的DataBind和回传回传、DataBind

2023-09-03 00:58:31 作者:や带着面具的小丑▍

这是一个普遍的如何做的DataBind工作的问题...

This is a general how does DataBind work questions...

我有一个简单的页面绑定(在ASPX code)一个GridView一个ObjectDataSource。

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

我可以看看在调用该ObjectDataSource看到,它被称为初始负载和每一个岗位后面的select()函数。我有一些逻辑发生在后背上,这将影响到GridView的数据,我想在后调用GridView.DataBind()后来回来后,我已经做了一些改动。

I can look in the Select() function called by the ObjectDataSource to see that it is called on the initial load and on every post back. I have some logic that happens on post backs that will affect the GridView's data, and I want to call GridView.DataBind() later on in the post back, after I've made some changes.

有没有一种方法,以prevent自动重新绑定是发生在每个帖子后面?这是否意味着我不能使用一个ObjectDataSource这个控制?

Is there a way to prevent the automatic rebinding that happens on each post back? Does this mean I can't use an ObjectDataSource for this control?

推荐答案

你的,你要寻找的细粒度控制是不可能的,需要背后的code正确。 ASP.NET的数据源对象都不过是一个痛苦的一**。你会发现,当你使用它们,你会得到的情况是这样一次又一次此起彼伏。

You're correct in that the fine grained control you're looking for is not possible and requires the code behind. ASP.NET's data source objects are nothing but a pain in the a**. You'll find that as you use them you'll get situations like this cropping up again and again.

有些问题,你会发现是:

Some of the problems you'll find are:

不强类型 在不灵活(如你注意到) 浑了presentation code

我已经采取做背后的code中所有的数据访问,并没有回头。

I've taken to doing all data access in the code behind and haven't looked back.