ASP ListView: How do I access the data that is databound to the rows?

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-06-04T12:48:11Z Indexed on 2010/06/11 12:43 UTC
Read the original article Hit count: 187

I want to access the data that was databound to my list view when handling list view events such as:

protected void List_ItemDataBound(object sender, ListViewItemEventArgs e)

or

protected void List_ItemCommand(object sender, ListViewCommandEventArgs e)

Inside the events, I can not access the data via somthing like Eval("ID")

Currently we are using a very hacky solution:

string id = e.Item.FindControl("lblID").Text;

Where lblID is a hidden control that is populated with data in the aspx file using:

<asp:Label ID="lblID" runat="server" Text='<%# Eval("ID") %>' />

My eyes bleed when I look at this, Is there a better way?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about databinding