Link to home
Start Free TrialLog in
Avatar of bemara57
bemara57

asked on

What's the difference between DataBinder.Eval and Bind?

I'm binding object properties to a GridView via the aspx page instead of the code-behind. I'm having trouble understanding the difference between DataBinder.Eval and Bind because they seem to do the same thing. Below is what I have in a web app. What caught my attention is that this wouldn't compile (parse error). Notice the dot notation of the object property Depth:

                            <asp:Literal ID="productDimensionsDepth" runat="server"
                                Text='<%# Bind("Dimensions.Depth") %>' />

But when I changed it like this, it worked fine:

                            <asp:Literal ID="productDimensionsWidth" runat="server"
                                Text='<%# DataBinder.Eval(Container.DataItem, "Dimensions.Width") %>' />

How come there is a difference? Are these identical?

                            <asp:Literal ID="productName" runat="server"
                                Text='<%# Bind("Name") %>' />

                            <asp:Literal ID="productName" runat="server"
                                Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' />
ASKER CERTIFIED SOLUTION
Avatar of NazoUK
NazoUK
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial