[英]Find value of dynamically added textbox
我從動態生成的html表中的文本框旁邊的數據集生成了一些問題。 我有5個問題和5個文本框。 因此,我需要找回一些文本框的值。
我正在遍歷數據集,並在其旁邊添加了一系列帶有文本框的問題。 但是,我需要為每個文本框生成一些唯一的ID嗎?
private void GenerateTable(int colsCount, int rowsCount, DataSet ds, DataSet ds2)
{
if (!IsPostBack)
{
int counter = 0;
List<TableRow> tableRowList = new List<TableRow>();
List<TableCell> tableCellList = new List<TableCell>();
List<Control> controlsList = new List<Control>();
foreach (DataTable dataTable in ds.Tables)
{
foreach (DataRow dataRow in dataTable.Rows)
{
TableRow tableRow = new TableRow();
TableCell tableCell = new TableCell();
TableCell tableCell2 = new TableCell();
TextBox textbox = new TextBox();
//textbox.ID = "TextBoxID";
TableRow tableRow2 = new TableRow();
TableCell tableCel2 = new TableCell();
tableCell.Text = dataRow["QUESTIONTEXT"].ToString();
if (dataRow["TYPEID"].ToString() == "1")
{
tableCell2.Controls.Add(textbox);
controlsList.Add(textbox);
}
tableRow.Cells.Add(tableCell);
tableRow.Cells.Add(tableCell2);
myTable.Rows.Add(tableRow);
tableRowList.Add(tableRow);
tableCellList.Add(tableCell);
tableCellList.Add(tableCell2);
counter++;
}
}
//TextBox tb = myTable.FindControl(TextBoxID) as TextBox;
我需要為每個文本框生成一些唯一的ID嗎?
是的... ID必須是唯一的。 具有多個具有相同id的元素的頁面是無效的
規格 :
id =名稱[CS]
此屬性為元素分配名稱。 此名稱在文檔中必須唯一。
但是,如果您根本不使用id
,則根本無法分配ID ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.