CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Difference between Eval() and BIND() DataBinding Expression method in ASP.Net
Submitted By Satheesh Babu B
On 11/16/2008 6:38:05 AM
Tags: ASP.Net,CodeDigest,Gridview  

 

To bind the database column value to the child control in a gridview, we can either use Bind() or Eval() methods.

 

<ItemTemplate>

                        <asp:Label ID="lblDOB" runat="server" Text='<%# Bind("DOB") %>'></asp:Label>

</ItemTemplate>

 

If you see the above code, we have used Bind() to bind DOB to the text property of Label control. Using Eval in the place of Bind will also work.

 

Eval() and Bind() methods

You can use the Eval method when the control will only display values. You can use the Bind method when users can modify a data value - that is, for data edit/update/view scenarios called two-way databinding. 

 

<asp:TemplateField HeaderText="URL">

                            <EditItemTemplate>

                                <asp:TextBox ID="txtURL" Width="100%" Text='<%# Bind("URL")%>' runat="server"></asp:TextBox>

                            </EditItemTemplate>

                            <ItemTemplate>

                                <asp:HyperLink ID="hplURL" Text='<%# Bind("URL") %>' NavigateUrl='<%# Bind("URL") %>' runat="server">[hplURL]</asp:HyperLink>

                            </ItemTemplate>

                        </asp:TemplateField>

 

 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..