repeater weirdness...
- Container.DataItem is a runtime alias for the DataItem for this specific item in the bound list.
- the type of DataItem is determined by the datasource
- Some examples (all C#)
- Array of Strings:
- <%# Container.DataItem %>
- Field from DataView:
- <%# ((DataRowView)Container.DataItem)["EmployeeName"] %>
- Property from a collection of objects:
- <%# ((Customer)Container.DataItem).CustomerName %>
- Non-String property from a collection of objects:
- <%# ((Customer)Container.DataItem).CustomerID.ToString() %>
- Pain in the ass... (ugly syntax because C# requires explicit casting - so we are given:)
- DataBinder.Eval()
- Helper function that figures out the syntax for you AND formats the result to a string!
- late bound and only supports basic data types
- takes 2 or 3 arguments
- first is data object to bind to
- for DataGrid, DataList and Repeater Container.DataItem is a single row
- Second is string name of field from data object you wish to display
- Third arg (optional) is a .NET formatting string
So - what does this all mean?
-
<%# DataBinder.Eval(Container.DataItem, "Cost", "{0:c}")%>
- where {placeholderNumber:formatCharacter} - so the 0th variable, make it currency
- (interesting to note if you change the servers global locale information to say China, you'll get the Yen symbol)