繁体   English   中英

在c#和asp.net中更新动态创建的文本框

[英]update dynamically created textbox in c# and asp.net

我有一个asp.net Web应用程序,其中用于生成文本框列表的方法取决于表中的计数,并在列末尾动态生成按钮以更新文本框中的值。我附有示例代码,以供参考,例如将c限制分配给5,以便在动态生成的按钮单击事件时如何更新此文本框控件。

样例代码:

TableRow rowpoint = new TableRow();
                    TableCell cellpoint = new TableCell();
                    cellpoint.Text = "Total Points";
                    rowpoint.Cells.Add(cellpoint);

                    for (int c = 0; c < 5; c++)
                    {

                        TableCell cellinput = new TableCell();
                        TextBox txtinput = new TextBox();

                        cellinput.Controls.Add(txtinput);
                        rowpoint.Cells.Add(cellinput);
                    }


                    TableCell totpoint = new TableCell();

                    totpoint.BackColor = System.Drawing.Color.FromArgb(221, 221, 221);

                    Button btnupdate2 = new Button();
                    btnupdate2.Text = "Update";
                    totpoint.Controls.Add(btnupdate2);
                    rowpoint.Cells.Add(totpoint);
                    tbl1.Rows.Add(rowpoint);
                    //End Adding Total Points

在创建文本框时,为每个文本框赋予唯一的ID。 创建按钮时添加按钮单击处理程序

btnupdate2.Click += new System.EventHandler(this.btnupdate2_OnClick)

然后编写下面的事件处理程序

protected void btnupdate2_OnClick(object sender, EventArgs e) {


}

在此内部使用FindControl来获取每个文本框。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM