1

Suppose I have a GridView whose data source is a list of type Meeting. Every Meeting object has a property of type Employee, and at the same time every Employee has a Name property. If I want to show the name of the Employee in a GridView, I should do this:

<asp:TemplateField>
    <ItemTemplate>
        <asp:Label Text='<%# Eval("Employee.Name") %>' runat="server" />
    </ItemTemplate>
</asp:TemplateField>

My question: Why I'm not able to do the same thing with Bind? When trying to display the property of a property using Bind, I get a compilation error. What are the differences in this case about using Eval or Bind?

English is not my first language, sorry for all possible mistakes.

Camilo
  • 108
  • 1
  • 6
  • You can do it with [eval](http://stackoverflow.com/questions/1130351/gridview-bound-with-with-properties-of-nested-class) – deostroll Mar 16 '14 at 05:05

1 Answers1

0

If you just need to display data on the screen from DataSource it’s enough to use Eval

But if you need to edit data inside of Grid you have to use Bind method. Because it provides two way binding you can read data from DataSource and you can write data back

If you try to edit some row in Data Grid and want to make some changes in code behind class in OnUdpdating event, data with Eval method will not be available instead of Bind method.

The difference between these two is that Eval is used for read only purpose and Bind is used for read/edit purpose. For example Eval can be used to bind the Text property of an asp.net Label control whereas Bind can be used to bind the asp.net TextBox control so that it can be edited to meet some requirement.

For more info see Mr.Darin Dimitrov answer

Community
  • 1
  • 1
Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
  • Ok, I understand that. I don't want to make any updates, I just want to show the data. The thing is if I use Bind instead of Eval in my previous example I get a compilation error. I thought that if I don't want to do any updates there is no difference between using Eval or Bind, and this is true most of the time, but if I want to display the property of a property, then I get an error when using Bind. – Camilo Mar 15 '14 at 23:16