rutledgj
asked on
need help understanding this code for item template in listview
I'm new to asp. I'm trying to use a listview control to display data from a database. I'm binding the datasource programmatically to a datatable.
The part I don't understand is this line which I found as a sample on the web:
<asp:ListView ID="lvHl7trans" runat="server">
<ItemTemplate>
<asp:Label runat="server" id="lbltransid" Text='<%# DataBinder.Eval(Container. DataItem, "ProductName")%>'></asp:La bel>
</ItemTemplate>
</asp:ListView>
and in particular the Text='<%# DataBinder.Eval(Container. DataItem, "ProductName")%>
part.
I'm trying to bind this label to the datatable column 'transid'. I don't understand if this is a differenct language (javascript maybe?) but I'd like to understand what each part of this statement means do I can use it in the future.
I'm assuming the <%# has a special meaning?
How about DataBinder.Eval()?
Can someone explain what is actually happening here?
Thanks
The part I don't understand is this line which I found as a sample on the web:
<asp:ListView ID="lvHl7trans" runat="server">
<ItemTemplate>
<asp:Label runat="server" id="lbltransid" Text='<%# DataBinder.Eval(Container.
</ItemTemplate>
</asp:ListView>
and in particular the Text='<%# DataBinder.Eval(Container.
part.
I'm trying to bind this label to the datatable column 'transid'. I don't understand if this is a differenct language (javascript maybe?) but I'd like to understand what each part of this statement means do I can use it in the future.
I'm assuming the <%# has a special meaning?
How about DataBinder.Eval()?
Can someone explain what is actually happening here?
Thanks
ASKER
So in my case if I want to bind this to transid column should it read like this:
<asp:Label runat="server" id="lbltransid" Text='<%# bind("transid")%>'></asp:L abel>
<asp:Label runat="server" id="lbltransid" Text='<%# bind("transid")%>'></asp:L
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Eval is a function that evaluates the value of the property with the name passed as its parameter.
Here is more detail about it:-
http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx
http://weblogs.asp.net/leftslipper/archive/2007/06/29/how-asp-net-databinding-deals-with-eval-and-bind-statements.aspx