Since I have not found a way to add values into the header of my repeater, I was forced to use literals or a new DataList/Repeater.

I only need to display a name and an ID in a header for a datalist, but cannot seem to make this happen! So I resorted to two options below and would like to know which one would be a better choice. Please take into consideration the performance and stability issues. Below are the two codes. One uses one Repeater and the other uses 5 literals with visibility. I have separated the sections for you with "---------------".

Unless someone knows how to access labels/literals or databind the HeaderTemplate in a repeater, this is what I have to do. Thanks!

This set are the Literals (5 literals total set with visibility on page_load):

<asp:Literal id="lblStoryHeader1" visible="false" runat="server">
<table width="525" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<th width="60%"><div align="left" style="margin: 22px 0px 3px 0px;"><strong>Stories about 
</asp:Literal>
<asp:Literal id="lblStoryHeader2" visible="false" runat="server" />
<asp:Literal id="lblStoryHeader3" visible="false" runat="server"></strong></div></th>
<td width="40%"><div align="right" style="margin: 22px 1px 0px 0px;"><a class="LC" href="/Vegas2/Stories/stories.aspx?CelebID=</asp:Literal><asp:Literal id="lblStoryHeader4" visible="false" runat="server" /><asp:Literal id="lblStoryHeader5" visible="false" runat="server">&New=true">Have a story to tell? Add one here!</a></div></td>
</tr>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="4" colspan="2"></td>
</tr>
</asp:Literal>

()

<asp:Repeater ID="CelebStories" runat="server">
<ItemTemplate>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="13" colspan="2"></td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="90%"><strong><%# DataBinder.Eval(Container.DataItem, "StoryTitle") %></strong></td>
<td width="10%" nowrap="nowrap" align="right"><div style="margin-right:20px;"><font color="#666666">Category:&nbsp;&nbsp;<%# DataBinder.Eval(Container.DataItem, "Category") %></font></div></td>
</tr>
<tr>
<td colspan="2"><div style="margin: 10px 10px 10px 10px;"><%# DataBinder.Eval(Container.DataItem, "Story") %>&nbsp;<font size="2" face="Verdana" color="#666666">... [<a href="/Vegas2/Stories/stories.aspx?StoryID=<%# DataBinder.Eval(Container.DataItem, "StoryID") %>">Full Story</a>]</div></td>
</tr>
<tr>
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="30%" class="subinfo">Posted By:&nbsp;&nbsp;<a href="/Vegas2/Users/profile.aspx?uaid=<%# DataBinder.Eval(Container.DataItem, "UserID") %>"><%# DataBinder.Eval(Container.DataItem, ("UserName")) %></a></td>
<td width="30%" class="subinfo">Date Posted:&nbsp;&nbsp;<%# String.Format("{0:d}", DataBinder.Eval(Container.DataItem, "DateCreated")) %></td>
<td width="30%" class="subinfo">Story Views:&nbsp;&nbsp;<%# FormatNumber(DataBinder.Eval(Container.DataItem, "StoryViews"),0) %></td>
<td width="10%" class="subinfo"><%# DataBinder.Eval(Container.DataItem, "PosNeg") %></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td height="13" colspan="2"></td>
</tr>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="2" colspan="2"></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
<tr>
<td height="13" colspan="2"></td>
</tr>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="4" colspan="2"></td>
</tr>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="10" colspan="2"></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

or Below (Repeater):

<asp:Repeater ID="StoryHeader" runat="server">
<ItemTemplate>
<table width="525" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<th width="60%"><div align="left" style="margin: 22px 0px 3px 0px;"><strong>Stories about <%# DataBinder.Eval(Container.DataItem, "CelebName") %></strong></div></th>
<td width="40%"><div align="right" style="margin: 22px 1px 0px 0px;"><a class="LC" href="/Vegas2/Stories/stories.aspx?CelebID=<%# DataBinder.Eval(Container.DataItem, "CelebID") %>&New=true">Have a story to tell? Add one here!</a></div></td>
</tr>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="4" colspan="2"></td>
</tr>
</ItemTemplate>
</asp:Repeater>

()

<asp:Repeater ID="CelebStories" runat="server">
<ItemTemplate>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="13" colspan="2"></td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="90%"><strong><%# DataBinder.Eval(Container.DataItem, "StoryTitle") %></strong></td>
<td width="10%" nowrap="nowrap" align="right"><div style="margin-right:20px;"><font color="#666666">Category:&nbsp;&nbsp;<%# DataBinder.Eval(Container.DataItem, "Category") %></font></div></td>
</tr>
<tr>
<td colspan="2"><div style="margin: 10px 10px 10px 10px;"><%# DataBinder.Eval(Container.DataItem, "Story") %>&nbsp;<font size="2" face="Verdana" color="#666666">... [<a href="/Vegas2/Stories/stories.aspx?StoryID=<%# DataBinder.Eval(Container.DataItem, "StoryID") %>">Full Story</a>]</div></td>
</tr>
<tr>
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="30%" class="subinfo">Posted By:&nbsp;&nbsp;<a href="/Vegas2/Users/profile.aspx?uaid=<%# DataBinder.Eval(Container.DataItem, "UserID") %>"><%# DataBinder.Eval(Container.DataItem, ("UserName")) %></a></td>
<td width="30%" class="subinfo">Date Posted:&nbsp;&nbsp;<%# String.Format("{0:d}", DataBinder.Eval(Container.DataItem, "DateCreated")) %></td>
<td width="30%" class="subinfo">Story Views:&nbsp;&nbsp;<%# FormatNumber(DataBinder.Eval(Container.DataItem, "StoryViews"),0) %></td>
<td width="10%" class="subinfo"><%# DataBinder.Eval(Container.DataItem, "PosNeg") %></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td height="13" colspan="2"></td>
</tr>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="2" colspan="2"></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
<tr>
<td height="13" colspan="2"></td>
</tr>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="4" colspan="2"></td>
</tr>
<tr>
<td colspan="2"><img width="525" src="/Vegas2/images/2w.gif" alt="" /></td>
</tr>
<tr>
<td height="10" colspan="2"></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

Oops, old code. Anyway, I updated it into one literal. If anyone can let me know how to add database values that are databound to the repeater into the HeaderTemplate, that would be great. Less times I have to hit the database, the better!

Solved it myself. Just used a literal but still would prefer a more stable method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.