Solved

need help understanding this code for item template in listview

Posted on 2012-04-11
3
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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