Solved

need help understanding this code for item template in listview

Posted on 2012-04-11
3
309 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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