jQuery and ASP.NET

December 23, 2009

Difference between Eval and Bind - Data Binding Expressions in ASP.NET




In simple words, the Eval function is used to define one-way binding (read only). The Bind function is used for two-way binding (read-write)

So in a control like the GridView or the FormView, when you have to display read only data using a label control, you would be using the Eval function whereas when you want to update a database field, you would be using a TextBox and thus using the Bind function.

Note: You can use the Bind function to retrieve the value of a databound field, just as Eval does.

Here’s an example:

<asp:FormView ID="FormView1" runat="server"
AllowPaging="True"
DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1">
<
EditItemTemplate>
CustomerName:
<asp:TextBox ID="txtCustName"
runat="server"
Text='<%# Bind("CName") %>'>
</
asp:TextBox>
</
EditItemTemplate>

<
ItemTemplate>
CustID:
<asp:Label ID="lblCustID"
runat="server"
Text='<%# Eval("CID") %>'>
</
asp:Label>
</
ItemTemplate>
</
asp:FormView>
You can read more on the Eval and Bind functions


Bookmark this link on del.icio.us (saved by 0 users)

Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter
Others Also Read..

comments

0 Responses to "Difference between Eval and Bind - Data Binding Expressions in ASP.NET"
 

Copyright 2010 All Rights Reserved DevCurry.com by Suprotim Agarwal