For a read-only (one way databinding) databound control, they are the same (I'm guessing Bind has slightly more overhead since it has more functionality, but I can't confirm that).
For 2 way databinding (using a datasource in which you want to update, insert, etc with declarative databinding), you'll need to use #Bind.
Simple as that. Eval is read only, Bind allows for data to go two ways.
Marked as answer by Rex Lin - MSFT on Apr 12, 2007 04:07 AM
Can someone please tell me the difference between these two. They seem to work the same.
Bruce
can't understand the difference either.
Procrastination is the thief of time. Do it NOW and its DONE. Finished!
And then, you'll be glad its done. You'll be satisfied and happy.
Then you can smile a big smile, do a little dance and have a glass of water :)
Ok, imagine a Gridview or a Formview control, with a typical itemtemplate, and an edititemtemplate.
If you use bind or eval in the itemtemplate, there will be no difference whatsoever in functionality.
If you, however, use Eval in the edit item template, the Eval-ed value will not be able to be passed to the Update method of the datasource. If you want to be able to pass the value (for example from a textbox) to the Update method of the datasource, you need
to use #Bind.
the Bind keyword works like Eval to display data and can retrieve the value you've entered when updating or inserting a record.
In addition, Bind is very useful in TemplateFields used in the GridView and DetailsView. Bind stores the value of the bound control property into a collection of values that the FormView control automatically retrieves and uses to compose the parameter list
of the insert or edit command. The argument passed to Bind must match the name of a field in the data container.
For example, the textbox in the code snippet provides the value for the notes field.
The .NET Framwork 2.0 introduces Eval(). Eval() is a shortcut for Container.DataItem(). Since Eval() uses Reflection, it causes overhead. From a optimization standpoint, it is better to use Container.DataItem().
Procrastination is the thief of time. Do it NOW and its DONE. Finished!
And then, you'll be glad its done. You'll be satisfied and happy.
Then you can smile a big smile, do a little dance and have a glass of water :)
brucec
Member
10 Points
34 Posts
#EVAL vs #BIND
Apr 11, 2007 05:38 PM|LINK
Can someone please tell me the difference between these two. They seem to work the same.
Bruce
shados
Star
12285 Points
2229 Posts
Re: #EVAL vs #BIND
Apr 11, 2007 06:49 PM|LINK
For 2 way databinding (using a datasource in which you want to update, insert, etc with declarative databinding), you'll need to use #Bind.
Simple as that. Eval is read only, Bind allows for data to go two ways.
sisieko
Member
107 Points
166 Posts
Re: #EVAL vs #BIND
Apr 11, 2007 07:19 PM|LINK
can't understand the difference either.
Procrastination is the thief of time. Do it NOW and its DONE. Finished!
And then, you'll be glad its done. You'll be satisfied and happy.
Then you can smile a big smile, do a little dance and have a glass of water :)
shados
Star
12285 Points
2229 Posts
Re: #EVAL vs #BIND
Apr 11, 2007 07:38 PM|LINK
If you use bind or eval in the itemtemplate, there will be no difference whatsoever in functionality.
If you, however, use Eval in the edit item template, the Eval-ed value will not be able to be passed to the Update method of the datasource. If you want to be able to pass the value (for example from a textbox) to the Update method of the datasource, you need to use #Bind.
KBrocksi_SEC
Contributor
3382 Points
627 Posts
Re: #EVAL vs #BIND
Apr 11, 2007 08:12 PM|LINK
Hi,
the Bind keyword works like Eval to display data and can retrieve the value you've entered when updating or inserting a record.
In addition, Bind is very useful in TemplateFields used in the GridView and DetailsView. Bind stores the value of the bound control property into a collection of values that the FormView control automatically retrieves and uses to compose the parameter list of the insert or edit command. The argument passed to Bind must match the name of a field in the data container.
For example, the textbox in the code snippet provides the value for the notes field.
sisieko
Member
107 Points
166 Posts
Re: #EVAL vs #BIND
Apr 11, 2007 11:00 PM|LINK
Procrastination is the thief of time. Do it NOW and its DONE. Finished!
And then, you'll be glad its done. You'll be satisfied and happy.
Then you can smile a big smile, do a little dance and have a glass of water :)
brucec
Member
10 Points
34 Posts
Re: #EVAL vs #BIND
Apr 12, 2007 01:00 PM|LINK
Yes, me too. Thanks for clearing that up, everyone.
brucec
Member
10 Points
34 Posts
Re: #EVAL vs #BIND
Apr 12, 2007 01:04 PM|LINK
HTH, hmmm. Wasn't Eval() available in .NET 1.1?
KBrocksi_SEC
Contributor
3382 Points
627 Posts
Re: #EVAL vs #BIND
Apr 12, 2007 06:17 PM|LINK
Hi,
...just to review, the databinding tags have been simplified a bit for ASP.NET 2.0, but you can still use the previous versions as well.
In ASP.NET 1.1 the databinding tags were:
ASP.NET 2.0 offer those as well as the following:
To be complete, you can also bind to configuration files as well:
For two way databinding, one could use the inline editing of a GridView or use either variation of the <%@ Bind(...) %> expressions for a FormView.
HTH,
brucec
Member
10 Points
34 Posts
Re: #EVAL vs #BIND
Apr 13, 2007 04:04 PM|LINK