1

I am trying to create an accessible accordion with the repeater. I need to populate a list in my headertemplate from an Eval in my ItemTemplate. I have a runat server but it's not shown in my codebehind. How can I populate the ul?

structure:

<asp:Repeater runat="server" ID="repeater1" OnItemDataBound="repeater1_ItemDataBound">
<HeaderTemplate>
<div class="accordion">
<ul class="tab-titles" role="tablist" runat="server" ID="tabtitles">
<li aria-controls="panel1" class="title" id="tab1" role="tab" tabindex="0">Tab 1</li>
<li aria-controls="panel2" class="title" id="tab2" role="tab" tabindex="0">Tab 2</li>
</ul>
</HeaderTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="category" runat="server" Text='<%# Eval("cat") %>' OnDataBinding="lblCat_DataBinding"></asp:Label>

code behind:

protected void lblCampus_DataBinding(object sender, EventArgs e)
    {
        // tabtitles not found, need to populate Tab 1 and Tab 2, not implemneted yet.
    }
PhilPursglove
  • 12,511
  • 5
  • 46
  • 68
runners3431
  • 1,425
  • 1
  • 13
  • 30
  • Could you post the full code of your repeater and your repeater1_ItemDataBound method? –  Apr 29 '15 at 13:56
  • the full code is just a bunch of sphagetti code with datatable and ado calls. Thhis repeater is basically all there is... – runners3431 Apr 29 '15 at 14:22
  • How are you trying to reference `tabtitles`? – entropic Apr 29 '15 at 14:25
  • @runners3431 I asked because the entire repeater isn't included and your event is not mentioned in the repeater code –  Apr 29 '15 at 15:22
  • @JunePaik Just as a html control, i need to create list items and then add it. Is there existing code for this? – runners3431 Apr 29 '15 at 15:30
  • @runners3431 It is still quite unclear to me what exactly you are trying to do. If you just have issues retrieving a certain value from your Eval functions, take a look at the answer by workabyte. It's easier to do it from the codebehind. However, it is also possible you're just implementing your repeater in a wrong way. Right now I only see a label which you can set in your item template, but your header template contains only fixed HTML. If you have an example on what you're trying to achieve, we would be able to help you better. I think you might have to look at nested repeaters. –  Apr 29 '15 at 23:33

1 Answers1

1

The header and footer for repeaters and other data controls get a little tricky as to when they actually exists in the event lifecycle. you may want to want to include the ul in the item template and maybe nest another repeater if needed.

Alternatively you can catch these on the ItemCreated event as well, see this answer on SO for more details as to pulling that.

 protected void rpter_ItemCreated(Object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Footer)
            {    
              e.Item.FindControl(ctrl);
            }
            if (e.Item.ItemType == ListItemType.Header)
            {

              e.Item.FindControl(ctrl);
            }
}
Community
  • 1
  • 1
workabyte
  • 3,496
  • 2
  • 27
  • 35