views:

422

answers:

2

Hello,

I have a nested repeater and i want to pass value in its header. here is my code so far.. The main problem is the id of the control in header template is also coming from code behind.

<asp:Repeater ID="RptrProgCategory" runat="server">

            <ItemTemplate>
        <asp:Repeater ID="RptrPrograms" runat="server">
            <HeaderTemplate><input type="hidden" id="<%= questvalue%>"/></HeaderTemplate>
                        <ItemTemplate>                      
    <a href="/"  id="catid" class="off"><%# DataBinder.Eval(Container.DataItem, "cat") %></a></li>
                                                    </ItemTemplate>
        </asp:Repeater>

            </ItemTemplate>

        </asp:Repeater>

I want value in questvalue from code behind.Any idea how to achieve this?

Edit: I wanted to put this value in a DataTable and bind that value in Repeater bcoz i want output like this may be <%# DataBinder.Eval(Container.DataItem, "questvalue") %> instead of <%= questvalue%>..but in tht case i am not able to find the control

Category1(id of hidden field )
  subcat1
  subcat2
  subcat3
Category2(id of hidden field)
  subcat4
  subcat5..and so on..
A: 
Repeater mainRepeater = this.Page.FindControl("RptrProgCategory") as Repeater;
Repeater nestedRepeater = mainRepeater.FindControl("RptrProgCategory") as Repeater;

You can then do a FindControl in nestedRepeater for questValue. Add a runat='server' to questvalue so that you can access it in code behind.

I am writing this from memory, syntax might not be correct but it should get you off in the right direction.

Picflight
the thing is Picflight, when we generally do FindControl in nestedRepeater we specifiy the id likeHiddenField _hidden = (HiddenField)nestedRepeater.Controls[0].FindControl("hiddenfieldid")but in my case i m sending id from code behind so how to specify it here.
AB
set the id of the control in the repeater to something like mycontrolId - and then on OnItemDataBound - (or even OnItemCreated) use findcontrol("mycontrolId") - and then change the id of the control to your questvalue param.
FiveTools
A: 

set the id of the control in the repeater to something like mycontrolId - and then on OnItemDataBound - (or even OnItemCreated) use findcontrol("mycontrolId") - and then change the id of the control to your questvalue param.

FiveTools