asp.net資料繫結之Eval和Bind 和等區別

來源:互聯網
上載者:User

Eval是asp.net1.1中常
用的綁定文法,它是“單向”的,即綁定時把資料來源上相應的值賦到該控制項上,Eval的任務就完成了
而Bind所謂的“雙向”就是:在綁定時,把
資料來源上相應的值賦到該控制項上,並且,在提交時,自動提取使用者在該控制項上輸入的值。

document.getElementById('Code_Closed_Text_145659').style.display='none';

document.getElementById('Code_Open_Image_145659').style.display='inline';

document.getElementById('Code_Open_Text_145659').style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" alt="" width="11" height="16" align="top">document.getElementById('Code_Open_Text_145659').style.display='none';
getElementById('Code_Closed_Image_145659').style.display='inline';
getElementById('Code_Closed_Text_145659').style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" alt="" width="11" height="16" align="top">Code

<
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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.