0

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>
            </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..
Matt Sach
  • 1,162
  • 16
  • 37
AB.
  • 849
  • 4
  • 14
  • 23
  • What's the point of a hidden field if you don't know the id? Are you sure you don't want the *value* to be dynamic? – Mark Brackett Mar 07 '10 at 13:51
  • actually there is some javascript connected to ID...and i can't change the javascript...so i am putting hidden field with ID from code behind to make that happen. – AB. Mar 07 '10 at 15:12

2 Answers2

0
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
  • 3,832
  • 13
  • 61
  • 90
  • the thing is Picflight, when we generally do FindControl in nestedRepeater we specifiy the id like HiddenField _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. Mar 07 '10 at 13:34
  • 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 Mar 07 '10 at 21:50
0

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
  • 5,970
  • 15
  • 62
  • 84