ASP.NET DropDownList1 数据绑定的效率
2009-09-11 15:40
423 查看
在CodeProject上看到一篇数据绑定的测试评论,该评论已经被MVP认可了,我对这样的结果也感到十分的惊讶,看来,以后在写代码的习惯上要稍微有些修改了. 先给出测试的代码: public void initList(DataTable dt) { DropDownList1.DataSource = dt; DropDownList1.DataTextField = "empName"; DropDownList1.DataValueField = "empNumber"; DropDownList1.DataBind(); } public void initList2(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList2.Items.Add(new ListItem(r["empName"].ToString(), r["empNumber"].ToString())); } } public void initList3(DataTable dt) { foreach (DataRow r in dt.Rows) { DropDownList3.Items.Add(new ListItem(r[0].ToString(), r[1].ToString())); } } initList的效率比initList2和initList3的效率低可能十倍以上(太可怕了,我是没有认真测试过,但是估计有点夸张),initList2和initList3的效率差不多,但是initList3的效率会比initList2的效率高些,因为使用列号的代码不用在绑定的时候绑定的名称不用转换为对应的下标,并关联的数据源中的数据.还有,使用列号的时候,会使用Cache的,但并不是每次都会用到.所以使用initList3的数据绑定才是效率最高的. |
相关文章推荐
- [ASP.NET] 将数据绑定到DropDownlist中的常见问题
- 《ASP.NET》数据绑定—DropDownList、ListBox
- ASP.NET中DropDownList控件的简单使用--DDL绑定数据库表中值,选择DDL中值直接检索数据
- ASP.NET MVC DropDownList数据绑定及使用详解
- ASP.NET中DropDownList控件的数据绑定的C#语言描述
- [Asp.Net]4种方法把数据绑定到Dropdownlist
- ASP.NET中dropdownlist 动态绑定数据的二种方法
- [ASP.NET]利用DataTable对DropDownList进行数据绑定
- Asp.net下用DropDownList绑定Xml数据
- ASP.NET中利用存储过程向DropDownList中绑定数据
- 理解asp.net中DropDownList编辑数据源,绑定数据库数据。
- ASP.NET中DropDownList下拉框列表控件绑定数据的4种方法
- asp.net中dropdownlist中绑定数据…
- ASP.NET数据绑定的效率
- ASP.NET 2.0的 GridView中模板列绑定DropDownList的数据处理
- ASP.NET dropdownlist绑定数据却显示System.Data.DataRowView
- asp.net ajaxtoolkit CascadingDropDown从数据库中读取数据绑定到DropDownList控件上
- ASP.NET 中 DropDownList+DataList(数据列表)的使用前台绑定
- ASP.net DropDownList数据绑定及使用详解
- ASP.NET中DropDownList控件的数据绑定的C#语言描述