views:

682

answers:

1

My Listview control contains 4 columns and 30 rows. I can retrieve the row number by using:

//get row of listview item
ListViewDataItem item1 = e.Item as ListViewDataItem;
int findMe = item1.DisplayIndex;

How do I then get values from one or all 4 columns?

I was trying:

this.lblReponseRoute.Text = item1.FindControl("routenameLabel").ID.ToString();

UPDATE1:

The final solution is:

//get row of listview item
ListViewDataItem item1 = e.Item as ListViewDataItem;
int findMe = item1.DisplayIndex;

//find label value
var routeLabel = (Label)ListView1.Items[findMe].FindControl("routenameLabel");
this.lblReponseRoute.Text = routeLabel.Text; 
+1  A: 

If routenameLabel is a server control, I believe you're going to have to cast it as such prior to accessing the properties:

var routeLabel = (Label)item1.FindControl("routenameLabel");
lblResponseRoute.Text = routeLabel.ID.ToString();

Do you get an error on the code you've posted?

Edit: Note that in your real code you'd want to test for null before casting to the Label.

Josh
thanks. I wasn't getting any specific error - just the ID of the label when I want it's value. I have edited my post with the final code solution.
John M