This is related to my earlier question, but I thought I’d simplify it and make a challenge out of it. Given the code below, can you change the value of ‘ChangeThisLabel’ from the code behind?
<asp:ListView ID='OuterListView' runat='server'> <LayoutTemplate> <asp:PlaceHolder ID='itemPlaceHolder' runat='server' /> </LayoutTemplate> <ItemTemplate> <%#Eval('outer_value')%> <br/> <asp:ListView ID='InnerListView' runat='server' DataSource='<%#Eval('inner') %>'> <LayoutTemplate> <asp:Label ID='ChangeThisLabel' runat='server' /> <asp:PlaceHolder ID='itemPlaceHolder' runat='server' /> </LayoutTemplate> <ItemTemplate> <%#Eval('inner_value')%> <br/> </ItemTemplate> </asp:ListView> </ItemTemplate> </asp:ListView>
I would suggest trying it yourself before submitting an answer, as I got a lot of suggestions in my earlier post that work fine for a single ListView, but fall down when going up against the nested ListView.
as it was mentioned in the other answer. in the code behind, on load, you can do this:
then cast it as a label and change the text. obviously you would iterate this code inside a loop so you do it for every label in ever inner list view of every outside list view.
And regarding answers to your other question, you were not clear that you wanted to access it from the code behind. Also you might want to post what you have tried, so that people know that you have tried different methods.
good luck!
edit: regarding your comment:
you are correct, but when you use FindControl(id), it will use the server side id to find the control. if you do: InnerListView.FindControl(‘ChangeThisLabel’) then it will find the right label regardless of the client side ID assigned to that control.