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>
|