簡體   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