Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

need help understanding this code for item template in listview

Posted on 2012-04-11
3
Medium Priority
?
341 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 2000 total points
ID: 37834638
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

963 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