Link to home
Start Free TrialLog in
Avatar of rutledgj
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:Label>
                                    </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
Avatar of BuggyCoder
BuggyCoder
Flag of India image

by using <%# %> we can insert any .net function in markup.
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
Avatar of rutledgj
rutledgj

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:Label>
ASKER CERTIFIED SOLUTION
Avatar of BuggyCoder
BuggyCoder
Flag of India 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