Page view counter

Formatting table in header template

Last post 06-17-2008 8:53 AM by Cliff_G. 3 replies.

Sort Posts:

  • Formatting table in header template

    06-17-2008, 6:07 AM
    • Loading...
    • Cliff_G
    • Joined on 05-21-2007, 7:24 AM
    • Posts 29
    • Points 20

    .Net 3.5, VB 

    I have a datalist which contains a list of contacts, and in the header template I specify the header columns for the labels and then have a table in the item template.

    What I have to do is hardcode the width of the columns in both the header and the item template so they are the same, is there any way on loading of the table to extract the width of the column and then apply this to the relevant column in the header?

    The current code is below:

    <asp:DataList ID="dlContacts" runat="server">

    <ItemStyle CssClass="DataListLineStyle" />

    <AlternatingItemStyle CssClass="DataListAlternatingLineStyle" />

    <HeaderTemplate>

    <table class="Table" border="0" cellpadding="0" cellspacing="0">

    <tr>

    <td colspan="6" class="CellHeader">

    Customer Contacts

    </td>

    </tr>

    <tr class="CellLabel">

    <td width="150px" align="left">

    Name

    </td>

    <td width="100px" align="center">

    Title

    </td>

    <td width="125px" align="center">

    Office Tel

    </td>

    <td width="125px" align="center">

    Mobile

    </td>

    <td width="175px" align="center">

    Email

    </td>

    <td width="125px" align="center">

    Fax

    </td>

    </tr>

    </table>

    </HeaderTemplate>

    <ItemTemplate>

    <table width="100%" class="Table" cellpadding="0" cellspacing="0" border="0">

    <tr>

    <td width="150px" align="left">

    <asp:TextBox ID="txtContact" runat="server" Text='<%# Eval("CUS_CONTACT") %>' Width="10px" Visible="False" CssClass="TextBoxDisplayCenterAlign"></asp:TextBox>

    <asp:LinkButton ID="lbContactName" runat="server"

    Text='<%# Eval("NAME") %>' CssClass="LinkButtonDisplayLeftAlign"

    CommandName="Select" Width="150px"></asp:LinkButton>

    </td>

    <td width="100px" align="center">

    <asp:TextBox ID="txtContactJobTitle" runat="server" Text='<%# Eval("TITLE") %>' Width="100px" CssClass="TextBoxDisplayCenterAlign"></asp:TextBox>

    </td>

    <td width="125px" align="center">

    <asp:TextBox ID="txtContactTel" runat="server" Text='<%# Eval("TEL_OFFICE") %>' Width="125px" CssClass="TextBoxDisplayCenterAlign"></asp:TextBox>

    </td>

    <td width="125px" align="center">

    <asp:TextBox ID="txtContactMobile" runat="server" Text='<%# Eval("TEL_MOBILE") %>' Width="125px" CssClass="TextBoxDisplayCenterAlign"></asp:TextBox>

    </td>

    <td width="175px" align="center">

    <asp:TextBox ID="txtContactEmail" runat="server" Text='<%# Eval("EMAIL") %>' Width="175px" CssClass="TextBoxDisplayCenterAlign"></asp:TextBox>

    </td>

    <td width="125px" align="center">

    <asp:TextBox ID="txtContactFax" runat="server" Text='<%# Eval("FAX") %>' Width="125px" CssClass="TextBoxDisplayCenterAlign"></asp:TextBox>

    </td>

    </tr>

    </table>

    </ItemTemplate>

    </asp:DataList>

  • Re: Formatting table in header template

    06-17-2008, 8:27 AM
    Answer
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 2:39 PM
    • Des Moines, IA
    • Posts 9,159
    • Points 85,497
    • Moderator
      TrustedFriends-MVPs

    Instead of trying to line-up your tables, why not start the Table within the HeaderTemplate, continue within the ItemTemplate, and close within the FooterTemplate. This way everything will be within one table and everything will line-up beautifully.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

  • Re: Formatting table in header template

    06-17-2008, 8:32 AM
    Answer
    • Loading...
    • mpaterson
    • Joined on 11-27-2006, 3:24 AM
    • Ipswich, MA
    • Posts 1,264
    • Points 4,541

    Instead of doing that you should use one table for the header and item templates.

    ie

    <HeaderTemplate>
         <table>
            <tr>
                <td>column 1</td><td>column 2</td>
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
             <tr>
                <td>....</td><td>....</td>
             </tr>
    </ItemTemplate>
    <FooterTemplate>
          </table>
    </FooterTemplate>

    If everything happens for a reason what is the reason for this error?
  • Re: Formatting table in header template

    06-17-2008, 8:53 AM
    • Loading...
    • Cliff_G
    • Joined on 05-21-2007, 7:24 AM
    • Posts 29
    • Points 20

    Big Smile Big thanks to you both - did not realise you could do that!

Page 1 of 1 (4 items)