When you are data binding you need to fetch the value of the object you're
databinding to. Typically this is a row from a database, and for simplicity
I'll keep that as my example. So you then need a column value form the row.
This is the typical syntax for that:
<%# DataBinder.Eval(Container.DataItem, "SomeColumn")%>
The DataBinder.Eval syntax is used to dynamically fetch a value from an object
(the row, in this case), and the value is specified by the string parameter.
The value in this case is the column name. This mechanism is used for flexibility,
since you could be using a DataReader, a DataSet, DataTable, DataView, or
any other custom object to bind to. It uses reflection to fetch the value.
Container is the control that was created for this row in the databinding
control. DataGridItem, GridViewRow, RepeaterItem, whatever. Container.DataItem
is the row you're databinding to. The control holds the rows that was used
to do the data binding.
You can use other syntaxes to do data binding, but they tend to be more tightly
couple type-wise with the data source you're binding to, and thus the syntax
sometimes requires casting and it makes it uglier (if you can believe it)
than the DataBinder.Eval syntax above.
-Brock
DevelopMentor
http://staff.develop.com/ballen Thank for your immediate answer.
I have still a question:
In some text book for ASP.NET, they use
<%# Container.DataItem("FieldName") %>
to present the filed data, but In ohters, they uese
<%# DataBinder.Eval(Container, "DataItem.FieldName") %>
What is the difference between them?
"Wilco Bauwer" <wi****@gmail.com>
???????:11**********************@g14g2000cwa.googl egroups.com... <%="bla" %> is equal to Response.Write("bla");
<%# %> means that you are binding against an object (e.g. this is
databinding syntax).
----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl