惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
量子位
V
V2EX
S
SegmentFault 最新的问题
月光博客
月光博客
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
博客园_首页
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
Y
Y Combinator Blog
The Cloudflare Blog
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
B
Blog
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed

博客园 - 疾风

Internet Explorer允许的URL最大长度为2083个字符(Maximum URL length is 2,083 characters in Internet Explorer) 古筝和古琴有什么区别? 认识CSS中absolute与relative BAT详细手册 iframe的使用 领域逻辑的实现分类 面向对象问答 用户点击Log In按钮后发生了什么?(续篇1) 用户点击Log In按钮后发生了什么? 微软的在线RSS阅读器 2003年至2006年项目总结 经常会有一些Gmail的邀请函 Visual Studio 2005 RTM的奇怪问题 在.Net代码中验证XML文档 2006年的一些目标 创建强类型的程序集 在.net中使用强类型来读取配置信息 自己做了一个单元测试的小工具---EasyTest.net How to gets the path for the executable file?
Eval和Bind
疾风 · 2006-10-13 · via 博客园 - 疾风

    在Asp.net(2.0?)中,我们可是使用两种方法来绑定数据,一为Eval,一为Bind。下面是使用这两种绑定方法的例子:

 1 <EditItemTemplate>
 2   <table>
 3     <tr>
 4       <td align=right>
 5         <b>Employee ID:</b>
 6       </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 的时候,还可以在<%# 和 %>写入代码来对内容作出处理,而处理的结果将作为返回值被传出来。