Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.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/1/asp.net/34.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# 行和单元格问题_C#_Asp.net - Fatal编程技术网

C# 行和单元格问题

C# 行和单元格问题,c#,asp.net,C#,Asp.net,您好,我在将表行和单元格添加到现有表中时遇到一些问题,我不确定原因 编辑:我试图实现的是在按钮上单击要添加到现有表中的另外三行。未将单击按钮时的额外表格行添加到表格中 使用ASP和C#,下面是我的代码,有人能告诉我我做错了什么吗 谢谢 ASP 好极了 身体运动 保罗·里维尔 铜猴子 C#代码隐藏 protected void btnAddEquipment_Click(object sender, EventArgs e) { tbleEquipmen

您好,我在将表行和单元格添加到现有表中时遇到一些问题,我不确定原因

编辑:我试图实现的是在按钮上单击要添加到现有表中的另外三行。未将单击按钮时的额外表格行添加到表格中

使用ASP和C#,下面是我的代码,有人能告诉我我做错了什么吗

谢谢

ASP


好极了
身体运动
保罗·里维尔
铜猴子
C#代码隐藏

        protected void btnAddEquipment_Click(object sender, EventArgs e)
    {
        tbleEquipment.Visible = true;
        btnAddEquipment.Visible = true;


        for (int c = 0; c < 4; c ++)
        {
            TableRow tr1 = new TableRow();
            for (int cc = 0; cc < 4; cc ++)
            {
                TableCell tc1 = new TableCell();
                tr1.Cells.Add(tc1);
            }
            tbleEquipment.Rows.Add(tr1);
        }    
    }
protectedvoidbtnaddequipment\u单击(对象发送方,事件参数e)
{
t leequipment.Visible=真;
btnAddEquipment.Visible=true;
对于(int c=0;c<4;c++)
{
TableRow tr1=新的TableRow();
对于(int cc=0;cc<4;cc++)
{
TableCell tc1=新的TableCell();
tr1.Cells.Add(tc1);
}
tbleEquipment.Rows.Add(tr1);
}    
}

您不能在TabelCell中设置任何内容

试着像这样检查一下,然后你就明白了

    for (int c = 0; c < 4; c++)
    {
        TableRow tr1 = new TableRow();
        for (int cc = 0; cc < 4; cc++)
        {
            TableCell tc1 = new TableCell();
            tc1.Text = "|empty Cell|";
            tr1.Cells.Add(tc1);
        }
        tbleEquipment.Rows.Add(tr1);
    }
for(int c=0;c<4;c++)
{
TableRow tr1=新的TableRow();
对于(int cc=0;cc<4;cc++)
{
TableCell tc1=新的TableCell();
tc1.Text=“|空单元格|”;
tr1.Cells.Add(tc1);
}
tbleEquipment.Rows.Add(tr1);
}
如果您在该单元格中添加文本框,请尝试这种方式

     for (int c = 0; c < 4; c++)
     {
        TableRow tr1 = new TableRow();
        for (int cc = 0; cc < 4; cc++)
        {
            TableCell tc1 = new TableCell();
            TextBox tb1 = new TextBox();
            tb1.ID = "txtTextBox" + cc.ToString();
            tc1.Controls.Add(tb1);
            tr1.Cells.Add(tc1);
        }
        tbleEquipment.Rows.Add(tr1);
     }
for(int c=0;c<4;c++)
{
TableRow tr1=新的TableRow();
对于(int cc=0;cc<4;cc++)
{
TableCell tc1=新的TableCell();
TextBox tb1=新的TextBox();
tb1.ID=“txtextbox”+cc.ToString();
tc1.控制。添加(tb1);
tr1.Cells.Add(tc1);
}
tbleEquipment.Rows.Add(tr1);
}
试试看


for(int i=0;i“无法将表行和单元格添加到现有表中”-你能详细说明一下吗?问题是表格正在生成,无法将其添加到现有表格中/某种样式问题/你没有获得tr本身。抱歉,编辑了描述-是的,问题是表格行没有在单击时添加,页面重新加载并没有错误,但没有最终结果。s就像回发问题一样,你能检查iPostBack吗?按钮导致回发-是否根据是否发生回发更改了简单的标签文本。第二个答案正是我想要的。非常感谢。
     for (int c = 0; c < 4; c++)
     {
        TableRow tr1 = new TableRow();
        for (int cc = 0; cc < 4; cc++)
        {
            TableCell tc1 = new TableCell();
            TextBox tb1 = new TextBox();
            tb1.ID = "txtTextBox" + cc.ToString();
            tc1.Controls.Add(tb1);
            tr1.Cells.Add(tc1);
        }
        tbleEquipment.Rows.Add(tr1);
     }
for(int i=0;i<4;i++)
{
   tbleEquipment.Rows.Add();
}