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"You can read more on the Eval and Bind functions
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>
Tweet
No comments:
Post a Comment