什么时候应该使用Page.DataBind()和Control.DataBind()? [英] When should you use Page.DataBind() versus Control.DataBind()?

查看:110
本文介绍了什么时候应该使用Page.DataBind()和Control.DataBind()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET中,您可以单独绑定控件(即 GridView1.DataBind()),也可以调用 Page.DataBind()绑定页面上的所有控件。

In ASP.NET, you can bind controls individually (i.e. GridView1.DataBind()) or you can call Page.DataBind() to bind all controls on the page.

两个电话之间有什么区别吗?有一次应该比另一个更好吗?

Is there any specific difference between the two calls? Are there times when one should be preferred over the other?

推荐答案

为了在Page.DataBind()和Control.DataBind ),这里是Microsoft 指导

For choosing between Page.DataBind() versus Control.DataBind(), here is the Microsoft guidance :

这两种方法的工作方式类似,主要的
的区别是所有数据源
绑定到它们的服务器控件
之后,Page.DataBind方法是
被调用,没有数据被呈现给
控件,直到你明确地调用
的WebBb $ b服务器控件的DataBind方法,或者直到你调用
页级别页面为止。 DataBind方法
通常,Page.DataBind(或DataBind)
从Page_Load事件调用。

"Both methods work similarly. The main difference is that all data sources are bound to their server controls after the Page.DataBind method is called. No data is rendered to the control until you explicitly call either the DataBind method of the Web server control or until you invoke the page-level Page.DataBind method. Typically, Page.DataBind (or DataBind) is called from the Page_Load event."

根据当前的页面情况,您会想要单独指定控制数据绑定的情况。对于绑定控件和控件绑定的详细控制级别,我选择了控件级的DataBind()方法。

There will be cases when you want specify control databinding individually, depending on the current page scenario. For a detailed level of control over which controls are bound and when controls are bound, I opt for the control-level DataBind() methods.

这篇关于什么时候应该使用Page.DataBind()和Control.DataBind()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆