欢迎来到飞鸟慕鱼博客,开始您的技术之旅!
当前位置: 首页知识笔记正文

Asp.net中的Eval和Bind

终极管理员 知识笔记 62阅读

(2.0?),我们用两种方法绑定数据,一种是Eval,一种是Bind。以下是使用这两种绑定方法的示例:1 edititem template 2 table 3 tr 4 TD align=right 5b employeeid :/B6/

28, 0, 0, 1)">td>
 7       <td>
 8         <%# Eval("EmployeeID") %>
 9       </td>
10     </tr>
11     <tr>
12       <td align=right>
13         <b>First Name:</b>
14       </td>
15       <td>
16         <asp:TextBox ID="EditFirstNameTextBox" RunAt="Server"
17           Text='<%# Bind("FirstName") %>' />
18       </td>
19     </tr>
20     <tr>
21       <td align=right>
22         <b>Last Name:</b>
23       </td>
24       <td>
25         <asp:TextBox ID="EditLastNameTextBox" RunAt="Server"
26             Text='<%# Bind("LastName") %>'  />
27       </td>
28     </tr>
29     <tr>
30       <td colspan="2">
31         <asp:LinkButton ID="UpdateButton" RunAt="server"
32           Text="Update" CommandName="Update" />
33         &nbsp;
34         <asp:LinkButton ID="CancelUpdateButton" RunAt="server"
35           Text="Cancel" CommandName="Cancel" />
36       </td>
37     </tr>
38   </table>
39 </EditItemTemplate>

    那么,它们之间有什么区别呢?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 的时候,还可以在<%# 和 %>写入代码来对内容作出处理,而处理的结果将作为返回值被传出来。


标签:
声明:无特别说明,转载请标明本文来源!