Iterating through a listview for specific ID?
I've got some labels in a listview, 2 per row. One contains a title, the other information. I want to change all the titles when the user presses a button that fires the ListViewSelectEventArgs. I think they have the same ID since they're from the ItemTemplate, so I thought that's how'd I target them. I'm just not sure how I'd step through the listview.
Here's my attempt:
int x = 1;
for( int i = 0 ; i < this.lvSteps.Controls[0].Controls.Count; i++ )
{
if ( this.lvSteps.Controls[0].Controls[i].GetType() == typeof(Label) &&
( this.lvSteps.Controls[0].Controls[i].ID == "lblStepNumber" ||
this.lvSteps.Contro开发者_开发知识库ls[0].Controls[i].ID == "lblNewStepNumber" ) )
{
Label lbl = this.lvSteps.Controls[0].Controls[i] as Label;
lbl.Text = "Step #" + x;
x++;
}
}
In your event handler for SelectedIndexChanging
lvSteps.Items(e.NewSelectedIndex).FindControl("lblStepNumber").Text = "whatever"
精彩评论