Creating a table inside a datalist

This is my DataList code, I define the table in the headertemplate and close it in the footerTemplate.

The problem with AlternatingItemStyle and ItemStyle is that they are not affected.

If I move the defenition of the table inside <ItemTemplate>, it works.

<asp:DataList ID="DataList1" runat="server" DataKeyField="ProductID" 
            DataSourceID="ObjectDataSource1" EnableViewState="False" 
            onitemdatabound="DataList1_ItemDataBound" Width="474px">
            <AlternatingItemStyle CssClass="AlternatingRowStyle" />
            <ItemStyle CssClass="RowStyle" />            


    <HeaderTemplate> 
      <table  cellspacing="0" cellpadding="0">
    </HeaderTemplate>
    <ItemTemplate>        
       <div id="Comment">

            <tr>
               <div id="Data1">
                 <td>
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                 </td>
                 <td>
                     <asp:CheckBox ID="CheckBox2" runat="server" />
                 </td>
                 <td>
                     <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("CategoryName") %>' />                                                          
                  </td>
               </div>                                          
            </tr>
            <tr>
               <td></td>
               <td></td>                                        
               <td>
                  <asp:Label ID="CategoryNameLabel" runat="server" Text="dfgfdgdg" />                     
               </td>                    
            </tr>                                                                           
        </div>        
    </ItemTemplate>

   <FooterTemplate>  </table></FooterTemplate>
</asp:DataList>
+3
source share
1 answer

Lupital, in my memory, the DataList control will generate table tags for you, you do not need to specify them in the header and footer.

For example:

<asp:DataList id="ItemsList"
       BorderColor="black"
       CellPadding="0"
       CellSpacing="0"
       RepeatDirection="Vertical"
       RepeatLayout="Table"
       BorderWidth="0"
       runat="server">

This should do what you are going to do with setting the "external" properties of the table of your element table.

Hope this should solve your alternating style issue.

+3
source

Source: https://habr.com/ru/post/1711097/


All Articles