Solved

need help understanding this code for item template in listview

Posted on 2012-04-11
3
287 Views
Last Modified: 2012-04-11
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
0
Comment
Question by:rutledgj
  • 2
3 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37834598
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
0
 

Author Comment

by:rutledgj
ID: 37834616
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>
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37834638
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now