Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
4.67/5 (3 votes)
See more:
What I want is width of TD tag should be automatically determine by its content.
I use following things for testing purpose.

HTML
<table cellpadding="0" cellspacing="0" style="width: 100%;">
        <tr>
            <td>
                Employee number*
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtEmployeeNumber">
            </td>
            <td>
                Employee name*
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtEmployeeName">
            </td>
        </tr>
    </table>


but what i get is all four column is divided in exactly four part.
My requirement is that, last column may contain remaining space.
But first three columns must have size equivalent to its content.


Thanks in advance..
Posted
Updated 14-Mar-11 2:00am
v2
Comments
#realJSOP 14-Mar-11 8:00am    
You had a lot more tags than necessary.

Okay, you didn't like the last answer, try this one:

<table width="100%">
    <tr>
        <td width="111">Employee number*</td>
        <td width="120"><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
        <td width="93">Employee name</td>
        <td><asp:TextBox ID="TextBox2" Width="100%" runat="server"></asp:TextBox></td>
    </tr>
</table>


The code above will make the first three columns as narrow as they can be, and the fourth with take up all the rest of the room. All you had to do was play around with a simple asp.net web page that contained nothing more than a simple table to figure it out.

Simply stated, a table is automatically going to make the columns all the same width. The only way I know of to address that is to set either fixed widths or percentages, of both on every column. You may even need to set alignment as well. Learn how to google.
 
Share this answer
 
v2
Its not possible....
you need to at least mention the first 3 columns width, so that the last column will take the width automatically.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900