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

'Like' us on our FaceBook page if you find this blog useful. Thanks!


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


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

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

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions