C# 如何在动态表上创建列跨度或行跨度 public分部类WebForm1:System.Web.UI.Page { } 受保护的无效页面加载(对象发送方、事件参数e) { } public void CreateRuntime_表() { int-tblRows=int.Parse(txtrow.Text); int-tblCols=int.Parse(txtcol.Text); 表tbl=新表(); tbl.BorderWidth=3; tbl.BorderStyle=BorderStyle.Solid; tbl.ID=“myTable”; 对于(int i=1;i
HTML列span和行span属性由C# 如何在动态表上创建列跨度或行跨度 public分部类WebForm1:System.Web.UI.Page { } 受保护的无效页面加载(对象发送方、事件参数e) { } public void CreateRuntime_表() { int-tblRows=int.Parse(txtrow.Text); int-tblCols=int.Parse(txtcol.Text); 表tbl=新表(); tbl.BorderWidth=3; tbl.BorderStyle=BorderStyle.Solid; tbl.ID=“myTable”; 对于(int i=1;i,c#,asp.net,C#,Asp.net,HTML列span和行span属性由TableCell类的columnsspan和rowsspan属性表示 在代码中,应该将这些属性的赋值添加到TableCell tc public partial class WebForm1 : System.Web.UI.Page { } protected void Page_Load(object sender, EventArgs e) { } public void CreateRunti
TableCell
类的columnsspan
和rowsspan
属性表示
在代码中,应该将这些属性的赋值添加到TableCell tc
public partial class WebForm1 : System.Web.UI.Page
{
}
protected void Page_Load(object sender, EventArgs e)
{
}
public void CreateRuntime_Table()
{
int tblRows = int.Parse(txtrow.Text);
int tblCols = int.Parse(txtcol.Text);
Table tbl = new Table();
tbl.BorderWidth = 3;
tbl.BorderStyle = BorderStyle.Solid;
tbl.ID = "myTable";
for (int i = 1; i <= tblRows; i++)
{
TableRow tr = new TableRow();
for (int j = 1; j <= tblCols; j++)
{
TableCell tc = new TableCell();
TextBox txtbox = new TextBox();
txtbox.Text = "Test Row:" + i + "Test Col:" + " " + j;
//Add the control to the table cell
tc.Controls.Add(txtbox);
tr.Controls.Add(tc);
}
tbl.Rows.Add(tr);
}
form1.Controls.Add(tbl);
}
protected void Unnamed_Click(object sender, EventArgs e)
{
CreateRuntime_Table();
}
public void CreateRuntime_Table()
{
int-tblRows=int.Parse(txtrow.Text);
int-tblCols=int.Parse(txtcol.Text);
//我建议使用int.TryParse和一些默认值
int colSpan=0;
int rowSpan=0;
int.TryParse(tbColspanName.Text,out colSpan);
int.TryParse(tbRowspanName.Text,out rowSpan);
表tbl=新表();
tbl.BorderWidth=3;
tbl.BorderStyle=BorderStyle.Solid;
tbl.ID=“myTable”;
对于(int i=1;i您的目标是什么:Winforms、WPF、ASP..?您应该始终正确地标记您的问题,以便人们可以在问题页面上看到它!您没有提到-如何-创建此动态表。这很重要,因为这是应该设置colspan的代码。请为您的问题添加相关的代码段。ClassSystem.Web.UI.WebControls.TableCell
有属性ColumnSpan
和RowSpan
。你应该给它们赋值。请你用代码详细说明一下。@MichalŠuvada感谢@Michal Suvada的重播,当我尝试重播时,它只是显示同一个表。ColumnSpan和RowSpan没有按预期工作。@SaifAK,然后你应该检查一下如果间距不是由文本框
填充
或边距
css属性引起的。最简单的方法是检查浏览器中的元素。
public void CreateRuntime_Table()
{
int tblRows = int.Parse(txtrow.Text);
int tblCols = int.Parse(txtcol.Text);
//I would recommend using int.TryParse with some defaults
int colSpan = 0;
int rowSpan = 0;
int.TryParse(tbColspanName.Text, out colSpan);
int.TryParse(tbRowspanName.Text, out rowSpan);
Table tbl = new Table();
tbl.BorderWidth = 3;
tbl.BorderStyle = BorderStyle.Solid;
tbl.ID = "myTable";
for (int i = 1; i <= tblRows; i++)
{
TableRow tr = new TableRow();
for (int j = 1; j <= tblCols; j++)
{
TableCell tc = new TableCell()
{
//assign entered col / row span
ColumnSpan = colSpan,
RowSpan = rowSpan
};
TextBox txtbox = new TextBox();
txtbox.Text = "Test Row:" + i + "Test Col:" + " " + j;
//Add the control to the table cell
tc.Controls.Add(txtbox);
tr.Controls.Add(tc);
}
tbl.Rows.Add(tr);
}
form1.Controls.Add(tbl);
}