Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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 - Fatal编程技术网

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# 如何在动态表上创建列跨度或行跨度 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

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 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的代码。请为您的问题添加相关的代码段。Class
System.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);
}