Eval是asp.net1.1中常 用的绑定语法,它是“单向”的,即绑定时把数据源上相应的值赋到该控件上,Eval的任务就完成了
而Bind所谓的“双向”就是:在绑定时,把 数据源上相应的值赋到该控件上,并且,在提交时,自动提取用户在该控件上输入的值。
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
< EditItemTemplate >
< asp:Label ID ="CityIDLabel1" runat ="server" Text ='<%# Eval("CityID") % > '> </ asp:Label >
< asp:TextBox ID ="CityTextBox" runat ="server" Text ='<%# Bind("City") % > '> </ asp:TextBox >
</ EditItemTemplate >
又例:
Eval:绑定的是只读数据的显 示;Bind:可以绑定只读数据也可以绑定更新数据,Bind方法还把字段和控件的绑定属性联系起来,使得数据控件(比如GridView等)的 Update、Insert和Delete等方法可以使用这种联系来作出相应的处理。
Eval 和 Bind绑定的数据在<%# %> 显示, 若对要显示的数据作修改或者操作也在<%# %> 中,例如:
1, 对显示的字符串作字符显示:
<%
# (
Eval
(
"
Address
"
)).ToString().SubString(
0
,
10
)
%>
显 示10位数的地址。
2, 对显示的信息作判断:
<%
# (
Eval
(
"
if_delete
"
)).ToString
==
"
yes
"
?
"
已删 除
"
:
"
未删除
"
%>
--------------------------------------------------------------------------------------------------------------------------------
<% %> An embedded code block is server code that executes during the page's render phase. The code in the block can execute programming statements and call functions in the current page class. http://msdn2.microsoft.com/en-gb/library/ms178135(vs.80).aspx
<%= %> most useful for displaying single pieces of information. http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx
<%# %> Data Binding Expression Syntax. http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx
<%$ %> ASP.NET Expression. http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx
<%@ %> Directive Syntax. http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx
<%-- --%> Server-Side Comments. http://msdn2.microsoft.com/en-US/library/4acf8afk.aspx
<%= %> most useful for displaying single pieces of information. http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx
<%# %> Data Binding Expression Syntax. http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx
<%$ %> ASP.NET Expression. http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx
<%@ %> Directive Syntax. http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx
<%-- --%> Server-Side Comments. http://msdn2.microsoft.com/en-US/library/4acf8afk.aspx