在Asp.net(2.0?)中,我们可是使用两种方法来绑定数据,一为Eval,一为Bind。下面是使用这两种绑定方法的例子:
1
2
3
4 5 Employee ID: 6 |
7 8 <%# Eval("EmployeeID") %> 9 |
10
11
12 13 First Name: 14 |
15 16 17 Text='<%# Bind("FirstName") %>' /> 18 |
19
20
21 22 Last Name: 23 |
24 25 26 Text='<%# Bind("LastName") %>' /> 27 |
28
29
30 31 32 Text="Update" CommandName="Update" /> 33 34 35 Text="Cancel" CommandName="Cancel" /> 36 |
37
38
39
那么,它们之间有什么区别呢?MSDN中说得很清楚啦,呵呵:
The Eval function is used to define one-way (read-only) binding.
The Bind function is used for two-way (updatable) binding.The Bind method takes the name of a data field to associate with the bound property.
也就是说,Eval用于显示只读的数据,而Bind既可以放置只读的数据又可以放置可以更新的数据。此外,Bind方法还把字段和控件的绑定属性联系起来,使得数据控件(比如GridView、FormView和其他数据库控件)的Update、Insert和Delete等方法可以使用这种联系来作出相应的处理。
另外,在使用Eval和Bind 的时候,还可以在<%# 和 %>写入代码来对内容作出处理,而处理的结果将作为返回值被传出来。
本文作者:疾风萧萧 来源:http://www.cnblogs.com/AchillesHuang/archive/2006/
CIO之家 www.ciozj.com 微信公众号:imciow