TableCell Widths

Discussion in 'ASP .Net' started by Tom, Dec 12, 2008.

  1. Tom

    Tom Guest

    I'm dynamically creating a table with the 1st cell having a checkbox control
    which is created and added to the cell...the next 3 cells contain textboxes.

    I can set the width of the 1st cell width and that works (width changes) but
    when I set the width of the cells that contain textboxes the width settings
    seemed to be ignored. I'm setting the width of the textboxes and that is
    working but it seems like the width of the cells are assuming the default
    width of the textboxes. If I don't set the width of the textboxes the cells
    and textboxes are the same width. When setting the width of the textbox the
    cell width is the same.
    Thanks...Tom

    textBoxTax = new TextBox();


    textBoxTax.Width = TAX_AMOUNT_WIDTH;

    tableCell = new TableCell();

    tableCell.BorderStyle = BorderStyle.Solid;

    tableCell.HorizontalAlign = HorizontalAlign.Right;

    tableCell.VerticalAlign = VerticalAlign.Top;

    tableRow.Cells.Add(tableCell);

    tableCell.Controls.Add(textBoxTax);
    Tom, Dec 12, 2008
    #1
    1. Advertising

  2. Tom,

    I'd try two things:

    First try setting the cell width via its style setting:
    tableCell.Style.Add(HtmlTextWriterStyle.Width, TAX_AMOUNT_WIDTH)
    Also, I think you may have to set the cell a few pixels wider than the text
    box. Try 2 pixels larger.

    Second try adding your textbox to the cell before you add the cell to the
    row. I've seen small differences crop up when adding objects to cells after
    the cell is added to the row (although I doubt this one will make a
    difference).

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche




    "Tom" <> wrote in message
    news:OyABHd$...
    > I'm dynamically creating a table with the 1st cell having a checkbox
    > control which is created and added to the cell...the next 3 cells contain
    > textboxes.
    >
    > I can set the width of the 1st cell width and that works (width changes)
    > but when I set the width of the cells that contain textboxes the width
    > settings seemed to be ignored. I'm setting the width of the textboxes and
    > that is working but it seems like the width of the cells are assuming the
    > default width of the textboxes. If I don't set the width of the textboxes
    > the cells and textboxes are the same width. When setting the width of the
    > textbox the cell width is the same.
    > Thanks...Tom
    >
    > textBoxTax = new TextBox();
    >
    >
    > textBoxTax.Width = TAX_AMOUNT_WIDTH;
    >
    > tableCell = new TableCell();
    >
    > tableCell.BorderStyle = BorderStyle.Solid;
    >
    > tableCell.HorizontalAlign = HorizontalAlign.Right;
    >
    > tableCell.VerticalAlign = VerticalAlign.Top;
    >
    > tableRow.Cells.Add(tableCell);
    >
    > tableCell.Controls.Add(textBoxTax);
    >
    >
    S. Justin Gengo, Dec 12, 2008
    #2
    1. Advertising

  3. Tom,

    Looking at the screenshot you sent I have something different to try. It
    looks as if you have the overall table set to a width of 100%. Try changing
    that and specifically setting the width on every column to a small pixel
    specific value as an experiment.

    When you set a table to a width of 100% .NET many times expands all table
    cells to take up parts of the overall width. By specifying specific values
    for each and every column width you should be able to control which cells
    are able to expand and which aren't.

    After you experiment with the widths to see if this works try setting the
    table to 100%, the very last column to a percentage width of say 75%, and
    all other columns to a fixed width of something like 100px. You should then
    be able to begin experimenting with various combinations of percent and
    fixed widths until you get the results you want.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche




    "Tom" <> wrote in message
    news:...
    > Thanks S.
    >
    > I tried your suggestions and still can't change the width of the cells w/
    > textboxes. I attached a screenshot in case it could help.
    >
    > "S. Justin Gengo"
    > <justin[remove-to-mail]@about-delete-to-mail-fortunate.com> wrote in
    > message news:...
    >> Tom,
    >>
    >> I'd try two things:
    >>
    >> First try setting the cell width via its style setting:
    >> tableCell.Style.Add(HtmlTextWriterStyle.Width, TAX_AMOUNT_WIDTH)
    >> Also, I think you may have to set the cell a few pixels wider than the
    >> text
    >> box. Try 2 pixels larger.
    >>
    >> Second try adding your textbox to the cell before you add the cell to the
    >> row. I've seen small differences crop up when adding objects to cells
    >> after
    >> the cell is added to the row (although I doubt this one will make a
    >> difference).
    >>
    >> --
    >> Sincerely,
    >>
    >> S. Justin Gengo, MCP
    >> Web Developer
    >>
    >> Free code library at:
    >> www.aboutfortunate.com
    >>
    >> "Out of chaos comes order."
    >> Nietzsche
    >>
    >>
    >>
    >>
    >> "Tom" <> wrote in message
    >> news:OyABHd$...
    >>> I'm dynamically creating a table with the 1st cell having a checkbox
    >>> control which is created and added to the cell...the next 3 cells
    >>> contain
    >>> textboxes.
    >>>
    >>> I can set the width of the 1st cell width and that works (width changes)
    >>> but when I set the width of the cells that contain textboxes the width
    >>> settings seemed to be ignored. I'm setting the width of the textboxes
    >>> and
    >>> that is working but it seems like the width of the cells are assuming
    >>> the
    >>> default width of the textboxes. If I don't set the width of the
    >>> textboxes
    >>> the cells and textboxes are the same width. When setting the width of
    >>> the
    >>> textbox the cell width is the same.
    >>> Thanks...Tom
    >>>
    >>> textBoxTax = new TextBox();
    >>>
    >>>
    >>> textBoxTax.Width = TAX_AMOUNT_WIDTH;
    >>>
    >>> tableCell = new TableCell();
    >>>
    >>> tableCell.BorderStyle = BorderStyle.Solid;
    >>>
    >>> tableCell.HorizontalAlign = HorizontalAlign.Right;
    >>>
    >>> tableCell.VerticalAlign = VerticalAlign.Top;
    >>>
    >>> tableRow.Cells.Add(tableCell);
    >>>
    >>> tableCell.Controls.Add(textBoxTax);
    >>>
    >>>

    >>

    >
    >
    >
    S. Justin Gengo, Dec 12, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. x

    capture a tablecell event

    Mr. x, Sep 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,119
    Mr. x
    Sep 2, 2003
  2. Serdar Kalaycý

    TableCell

    Serdar Kalaycý, Jun 30, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    580
    Karl Seguin
    Jun 30, 2003
  3. May
    Replies:
    0
    Views:
    370
  4. Jurjen de Groot

    Inserting text into TableCell at runtime

    Jurjen de Groot, Aug 18, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    477
    Xavier MT
    Aug 18, 2003
  5. Brian K. Williams

    TableCell oTableCell = new TableCell(); noWrap?

    Brian K. Williams, Apr 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,501
    Brian K. Williams
    Apr 30, 2004
Loading...

Share This Page