Dynamic header output in Repeater control?

Discussion in 'ASP .Net' started by Steve Franks, Sep 10, 2005.

  1. Steve Franks

    Steve Franks Guest

    OK this is driving me nuts - hope someone can help.

    I am searching for a way to dynamically output a value within the
    HeaderTemplate section of a Repeater control. Is this possible?

    It is obvious how to do this in the ItemTemplate section, but how can I do
    this in the Header section?

    Consider the excerpt I included at the bottom of this message. In this the
    DataBinder.Eval is used to dynamically output the ItemTemplate and this
    works great.However in the area marked "UNIQUE TITLE HERE" I want to
    dynamically write out the value of a particular variable as the title for my
    table and I cannot figure out how to do this.

    This is especially challenging for me because I created a .ascx file that
    contains the header, and then I am using:
    Repeater1.HeaderTemplate = Page.LoadTemplate("myheader.ascx");
    to load it.

    I am doing it this way because my header has a ton of HTML and I need to
    output these tables throughout my site, so rather than keep repeating blocks
    of the same HeaderTemplate section (except fot the title!) all over the
    place, I've used this approach.

    If I could figure out a way for the .ascx to access a variable within my
    ASP.NET page, then I could just do this in my header template:

    <tr><td colspan=2> <% Response.Write(varFromAspNetPage);
    %> </td></tr>

    Any ideas? Thanks.

    <asp:Repeater id=Repeater1 runat="server">

    <HeaderTemplate>

    <table border=1>
    <tr><td colspan=2> UNIQUE TITLE HERE </td></tr>
    <tr>
    <td><b>Company</b></td>
    <td><b>Symbol</b></td>
    </tr>

    </HeaderTemplate>

    <ItemTemplate>

    <tr>
    <td> <%# DataBinder.Eval(Container.DataItem, "Name") %>
    </td>
    <td> <%# DataBinder.Eval(Container.DataItem, "Ticker") %>
    </td>
    </tr>

    </ItemTemplate>

    <FooterTemplate>

    </table>

    </FooterTemplate>

    </asp:Repeater>

    Container.DataItem is NULL when ASP.NET is processing the header, so I do
    not know how I can dynamically get a value in to the header!

    Thanks,

    Steve
     
    Steve Franks, Sep 10, 2005
    #1
    1. Advertising

  2. Steve Franks

    jasonkester Guest

    Any reason you don't put the Repeater into a UserControl, rather than
    trying to stuff a UserControl into your Repeater? And why does it
    matter to you that your code goes into the HeaderTemplate at all? Why
    not just drop any HTML to open your table structure in front of the
    Repeater, then close the table outside the Repeater?

    I've been using Repeaters for years, and have never come across a good
    reason to bother with HeaderTemplate and FooterTemplate. What exactly
    are you trying to accomplish that requires you to use them?

    Jason Kester
    Expat Software Consulting Services
    http://www.expatsoftware.com/
     
    jasonkester, Sep 10, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    905
  2. Alan Silver
    Replies:
    5
    Views:
    17,173
    priyen.khatri
    Aug 13, 2009
  3. Gibs
    Replies:
    0
    Views:
    2,232
  4. mlt
    Replies:
    2
    Views:
    916
    Jean-Marc Bourguet
    Jan 31, 2009
  5. Yvonne

    User Control used in Repeater, but no output

    Yvonne, Nov 14, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    157
    Yvonne
    Nov 15, 2006
Loading...

Share This Page