c# - ASP.NET - 如何在 C# 表上设置单元格宽度百分比

标签 c# css asp.net .net webforms

大家好!我有一个 System.Web.UI.WebControls.Table,单元格(控件)的宽度(默认为 20%)。我想改变这个百分比 -> 40%/20%/20%/10%/10%

我想要关注:

enter image description here

如何在这个单元格(控件)上设置不同的宽度

这是我的代码:

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);

结果:

enter image description here

最佳答案

改为将宽度添加到 TableCell。使用这个:

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

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

更新:

对于文本框:

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

对于表格单元格:

TableCell tCellOne = new TableCell();
 tCellOne.Style.Add("width", "40%");
 tCellOne.Controls.Add(txt11);
 tRow1.Cells.Add(tCellOne);

关于c# - ASP.NET - 如何在 C# 表上设置单元格宽度百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36861893/

相关文章:

C# UTF-8编码问题

c# - 检测 Microsoft Teams 中当前是否正在进行 session 或通话

c# - 为什么我必须修改 web.config 才能启用调试?

css - 如何在 GridMvc 3.0.0 中为行动态着色

asp.net - 在 GridView 中显示本地时间

C# HtmlAgilityPack 内部 html 在附加节点后不改变

c# - 如果 Excel 列在 asp.net c# 中具有某些值,则提示消息

javascript - 如何从 html/css 页面中的 excel 表中获取数据?

angular - 带 Angular 路由器导出的柔性布局(柔性盒)

jquery - 尝试使用 hasClass() 实现 if 语句,但它不起作用