1

I am trying to modernize this site. I have a report table being generated in the old style like:

Dim sTable = "<table class=""stat"">"
sTable = sTable & "<thead><tr><th colspan=20><Status Report: " & Session("ProcessYear") & "</th></tr>"

I am converting this into a Repeater, but I am at a loss as to how to include session data in the <HeaderTemplate>. I have:

<asp:Repeater id="Dashboard" runat="server">
<HeaderTemplate>
    <table class="stat">
        <thead>
            <tr><th colspan="20">Appeal Status Report: ???? </th></tr>
...

Some candidates are asp:PlaceHolder, and something like <%# ((RepeaterItem)Container.Parent.Parent).DataItem %> (see Accessing parent data in nested repeater, in the HeaderTemplate), but I'm at a loss as to what that is referencing.

Not in a position to refactor out the Session dependencies, unfortunately. Any thoughts? I'm fairly new to ASP.NET. My CodeFile for this page is in VB.NET.

Osan
  • 191
  • 1
  • 2
  • 13

1 Answers1

1

You need to look into On Item Data Bound event, so you can do some code-behind work during binding.

You'll want to check the item object, determine if its a header row, then access your session object.

Rough adaptation might look like:

ASPX

<asp:Repeater id="Dashboard" runat="server" OnItemDataBound="ItemDataBound">
<HeaderTemplate>
    <table class="stat">
        <thead>
            <tr>
                <th colspan="20">
                    Appeal Status Report: <asp:Label ID="YourLabel"/>
                </th>
            </tr>
        ...
    ...
...

Code Behind

void ItemDataBound(Object Sender, RepeaterItemEventArgs e) 
{
    if (e.Item.ItemType == ListItemType.Header) 
    {
        ((Label)e.Item.FindControl("YourLabel")).Text = Session["YourSession"];
    }
}

You can also do things with the footer, item and alternating items here as well.

Nate
  • 28,586
  • 21
  • 107
  • 177