Repeater Difficulties

  • Thread starter Philip Townsend
  • Start date
P

Philip Townsend

I have a repeater control that writes an HTML table. Itv needs to
display a header in the first row, then a list of records produced from
a SQL table. The header text is also produced from the SQL query. The
items within the <ItemTemplate> section appear as needed, however, the
header text (which is contained in the <HeaderTemplate> section) does
not. Here is the code sample:

<asp:Repeater ID="rptLinks" Runat="server">
<HeaderTemplate>
<tr><td
colspan="2"><%#DataBinder.Eval(Container.DataItem,"sectionTitle")%></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="font-size:8pt">
<td width="10"><img src="images/bullet.gif" vspace="1"
hspace="1"></td>
<td width="140"><a
href="abs.aspx?pgID=<%#DataBinder.Eval(Container.DataItem,"pageID")%>"><
%#DataBinder.Eval(Container.DataItem,"pageTitle")%></a></td>
</tr>
</ItemTemplate>
</asp:Repeater>

The repeater object is bound to a Dataset in the following:


String PType = Request.QueryString["pgID"].ToString();
DataSet ds = new DataSet();
SqlConnection cnx = new
SqlConnection(ConfigurationSettings.AppSettings["mainconn"].ToString());
SqlCommand cmd = cnx.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "prLeftNavLinks";
cmd.Parameters.Add("@pageID",SqlDbType.Int);
cmd.Parameters["@pageID"].Value = Int32.Parse(PType);

SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds,"links");
rptLinks.DataSource = ds;
rptLinks.DataBind();

da.Dispose();
cmd.Dispose();
cnx.Dispose();

Any ideas as to why the headertext does not render in the repeater
control? Thanks!
 
M

Michael

Well if you want an idea, I don't belive you can use that
<%#DataBinder.Eval(Container.DataItem,"sectionTitle")%> stuff in the
HeaderTemplate, because there is no data there to be looked at yet. What I
believe you can do is pop an asp control in there and set that value from
code.

<HeaderTemplate>
<tr><td
colspan="2"><asp:label id="mySectionLabel" runat="server" /></td>
</tr>
</HeaderTemplate>

then somewhere down in your code

SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds,"links");
mySectionLabel.text = ds.myDataTableName(0).sectionTitle 'Typed Dataset
mySectionLabel.text = ds.tables("myDataTableName").rows(0)("sectionTitle")
'unTyped Dataset (I think that syntax is correct..I took one look at that
and learned how to use typed Datasets :) )
rptLinks.DataSource = ds;
rptLinks.DataBind();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top