tags:

views:

237

answers:

1

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

The problem is with AlternatingItemStyle and ItemStyle that they don't effect.

If i move the table defenition inside <ItemTemplate> it does work.

<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>
A: 

Lupital, from my recollection, the DataList control will generate the table tags for you, you don't 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 accomplish what you are looking to do with setting up the 'outer' table properties of your table of items.

Hopefully, that should solve your alternating style problem.

Jay S
yes, but i don't want on my page to have many tables (table for every item)
The above code should generate one outer table, and each row will be your item template. From what I recall it will generate a TR/TD around each item template.
Jay S