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;
If
routenameLabelis a server control, I believe you’re going to have to cast it as such prior to accessing the properties: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.