5

Hellooo, everyone! I have a System.Web.UI.WebControls.Table with cells(controls) with Width (20% by default). I want to change this Percentage -> 40% / 20% / 20% / 10% / 10%

I want following:

enter image description here

How to set different Width on this cells(controls)?

This is my code:

Table myTbl = new Table();
TableRow tRow1 = new TableRow();

    //Row1 Cells Controls

            TextBox txt11 = new TextBox();
            txt11.ID = "txtDest11";
            txt11.Height = 19;
           //txt11.Width = Unit.Percentage(40);

            TextBox txt12 = new TextBox();
            txt12.ID = "txtKmInCity12";
            txt12.Height = 19;

            TextBox txt13 = new TextBox();
            txt13.ID = "txtKmOutCity13";
            txt13.Height = 19;

            DateTimeControl dt11 = new DateTimeControl();
            dt11.DateOnly = true;
            dt11.ShowWeekNumber = true;
            dt11.LocaleId = 1026;

            DateTimeControl dt12 = new DateTimeControl();
            dt12.DateOnly = true;
            dt12.ShowWeekNumber = true;
            dt12.LocaleId = 1026;

            tRow1 = new TableRow();
            tRow1.Visible = true;

            TableCell tCellZero = new TableCell();
            tCellZero.Controls.Add(rowNo);
            tRow1.Cells.Add(tCellZero);

            TableCell tCellOne = new TableCell();
            tCellOne.Controls.Add(txt11);
            tRow1.Cells.Add(tCellOne);

            TableCell tCellTwo = new TableCell();
            tCellTwo.Controls.Add(dt11);
            tRow1.Cells.Add(tCellTwo);

            TableCell tCellThree = new TableCell();
            tCellThree.Controls.Add(dt12);
            tRow1.Cells.Add(tCellThree);

            TableCell tCellFour = new TableCell();
            tCellFour.Controls.Add(txt12);
            tRow1.Cells.Add(tCellFour);

            TableCell tCellFive = new TableCell();
            tCellFive.Controls.Add(txt13);
            tRow1.Cells.Add(tCellFive);

            myTbl.Rows.Add(tRow1);

Result :

enter image description here

1 Answer 1

13

Add width to TableCell instead. Use this:

TableCell myTableCell = new TableCell();
myTableCell.Width = new Unit("25%");

OR

myTableCell.Style.Add("width", "25%");

UPDATE:

For textboxes:

TextBox txt11 = new TextBox();
txt11.ID = "txtDest11";
txt11.Height = 19;
txt11.Style.Add("width", "100%");

For TableCells:

TableCell tCellOne = new TableCell();
 tCellOne.Style.Add("width", "40%");
 tCellOne.Controls.Add(txt11);
 tRow1.Cells.Add(tCellOne);
Sign up to request clarification or add additional context in comments.

5 Comments

@Gohyu, you've mentioned Width (20% by default) in OP. Have you set width of textbox or tablecell? Where did you set the width (aspx or code-behind)?
On textbox in tablecell
I have not set anything to the width.
So it means each TableCell has 20% width. And you need to set width in percentage of each Textbox contained in individual TableCell?
@Gohyu, Check my update to see if helps. Basically, set width for both tablecell and textbox.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.