Repeater Difficulties

Discussion in 'ASP .Net' started by Philip Townsend, Jan 9, 2004.

  1. 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!


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Philip Townsend, Jan 9, 2004
    #1
    1. Advertising

  2. Philip Townsend

    Michael Guest

    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();




    "Philip Townsend" <> wrote in message
    news:...
    > 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!
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Michael, Jan 9, 2004
    #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. Philip Townsend

    Caching difficulties (control level)

    Philip Townsend, Aug 4, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    325
    Philip Townsend
    Aug 4, 2003
  2. sonic
    Replies:
    3
    Views:
    490
    sonic
    Jan 12, 2005
  3. sonic
    Replies:
    0
    Views:
    290
    sonic
    Jan 12, 2005
  4. Robert
    Replies:
    3
    Views:
    576
    Tris Orendorff
    Oct 6, 2003
  5. ketil v

    COM - java difficulties

    ketil v, Jan 22, 2004, in forum: Java
    Replies:
    3
    Views:
    368
    ketil v
    Jan 23, 2004
Loading...

Share This Page