[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1598
  • Last Modified:

Datalist produces extra <tr><td></td></tr>

Hi,

I have an ASCX control with a Datalist inside. This datalist only defines a <headerTemplate> and <ItemTemplate>
and in each, the markup for a single table row.
When rendered it instead produces an extra table row rather than only the one I defined. How do I fix this?

See below:

 UNRENDERED HTML
--------------------------
<asp:DataList ID="dlCategories" runat="server" CellSpacing="0" CellPadding="3" Width="100%">
    <HeaderTemplate>
        <tr>
            <td class="moduletitles" colspan="2">
                Categories
            </td>
        </tr>
        <tr>
            <td class="modulelinks">
                   <asp:HyperLink CssClass="modulelinks" ID="hpCategories" NavigateUrl="~/default.aspx" runat="server">All</asp:HyperLink>
            </td>
            <td class="modulelinks" align="right">
            <asp:HyperLink ID="hpRSS" runat="server" NavigateUrl="~/rss.aspx" ImageUrl="~/webfeed.gif"></asp:HyperLink></td>
        </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td class="modulelinks">
                    &nbsp;&nbsp;<asp:HyperLink CssClass="modulelinks" ID="hplCategories" NavigateUrl='<%# "~/category.aspx?c=" + DataBinder.Eval(Container.DataItem, "CategoryID") %>' runat="server"><%# DataBinder.Eval(Container.DataItem, "CategoryName") %></asp:HyperLink>
            </td>
            <td class="modulelinks" align="right">
                <asp:HyperLink ID="hplRSS" runat="server" NavigateUrl='<%# "~/rss.aspx?c=" + DataBinder.Eval(Container.DataItem, "CategoryID") %>' ImageUrl="~/webfeed.gif"></asp:HyperLink>
            </td>
        </tr>
    </ItemTemplate>
</asp:DataList>


================

RENDERED IN BROWSER ( * - marks unwanted and undefined rows )
------------------------------

<table id="categorymodule_dlCategories" style="width: 100%; border-collapse: collapse;" border="0" cellpadding="3" cellspacing="0">
      <tbody>

        *<tr>
            <td>
        </td></tr>*

        <tr>

            <td class="moduletitles" colspan="2">
                Categories
               
            </td>
        </tr>
        <tr>
            <td class="modulelinks">
                    &nbsp;&nbsp;<a id="categorymodule_dlCategories_ctl00_hplCategories" class="modulelinks" href="default.aspx">All</a>
            </td>

            <td class="modulelinks" align="right">
            <a id="categorymodule_dlCategories_ctl00_hpRSS" href="rss.aspx"><img src="webfeed.gif" style="border-width: 0px;"></a></td>
        </tr>
   
      <tr>
            <td>
        </td></tr><tr>
            <td class="modulelinks">
                    <a id="categorymodule_dlCategories_ctl01_hpCategories" class="modulelinks" href="category.aspx?c=1">General</a>

            </td>
            <td class="modulelinks" align="right">
                <a id="categorymodule_dlCategories_ctl01_hplRSS" href="rss.aspx?c=1"><img src="webfeed.gif" style="border-width: 0px;"></a>
            </td>
        </tr>
   
      *<tr>
            <td>
        </td></tr>*
       
        <tr>
            <td class="modulelinks">

                    &nbsp;&nbsp;<a id="categorymodule_dlCategories_ctl02_hpCategories" class="modulelinks" href="category.aspx?c=2">Cuzco</a>
            </td>
            <td class="modulelinks" align="right">
                <a id="categorymodule_dlCategories_ctl02_hpRSS" href="rss.aspx?c=2"><img src="webfeed.gif" style="border-width: 0px;"></a>
            </td>
        </tr>
   
      
</tbody></table>

0
deecree
Asked:
deecree
1 Solution
 
HappyFunBallCommented:
You may want to switch to an asp:Repeater instead of the asp:DataList.  I don't believe you can easily stop the the table row tags from showing up (unless you override the Render method or something like that).

0
 
deecreeAuthor Commented:
Yes, you seem to be right. I guess the repeater will do.
Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now