声明式数据绑定与ADO.NET在code-背后 [英] Declarative databinding vs. ADO.NET in code-behind

查看:110
本文介绍了声明式数据绑定与ADO.NET在code-背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近试图了解ASP.NET GridView的我所看到的例子MST使用数据源直接在ASPX标记声明。例如...

In recent attempts to understand the ASP.NET GridView I have seen mst examples make use of a datasource declared directly in the ASPX markup. For example ...

<asp:SqlDataSource ID="productDataSource" Runat="server" 
 SelectCommand="SELECT [ProductName], [UnitPrice], 
 [UnitsInStock], [QuantityPerUnit] FROM [Products]"
    ConnectionString=
    "<%$ ConnectionStrings:NWConnectionString %>">
</asp:SqlDataSource>

我已经看到了很多这种声明的数据源作为使用ADO.NET来访问数据,而不是我被教导的方式(并亲自preFER),然后将在code-的数据源控件后面。

I have seen a lot this sort of declarative datasource as opposed to the way I was taught (and personally prefer) of using ADO.NET to access data and then set the controls datasource in the code-behind.

是否有优势,使用这种新型的ASPX数据源申报?有什么利弊?

Is there an advantage to using this new type of datasource declaration in the ASPX? What are the pros and cons?

推荐答案

的做数据绑定的声明方式的一个缺点是寻呼效率不高。在GridView会拉的所有记录从数据库中,然后它只会显示你的页面。如果你有1,000,000记录时,,这是不会要快。执行绑定自己,你只能拉你需要的记录。

One disadvantage of the declarative way of doing the data binding is that the paging is not efficient. The gridview will pull all records from the database, and then it will only show you your page. If you have 1,000,000 records, that is not going to be fast. Doing the binding yourself, you can only pull the records you need.

有关简单和小的表,所述声明性方法需要更少的开发时间,和寻呼和排序是内置的。

For simple and small tables, the declarative method requires less development time, and the paging and sorting are built in.

对于几乎所有现实世界的GridView的我曾上查询,以建立数据集的复杂性做出了声明式的方法并不可行。

For almost all real-world gridviews I have worked on, the complication of the queries to build the data set has made the declarative method not feasible.

这篇关于声明式数据绑定与ADO.NET在code-背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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