我现在正在制作一个单词编写器,它将从我的程序中输入的内容中编写一个单词文件。它工作得很好buuut。当我在表格中添加一些文本框时,他们会得到一个单独的名称,但是当我点击保存时,如何选择其中一个并从中获取文本字段?
这是我的表填充
private void filltabel()
{
for (int i = 1; i <= ddlServer.SelectedIndex; i++)
{
Label label = new Label();
label.Text = "<h3>Server " + i + "</h3>";
TableRow trow = new TableRow();
Table1.Rows.Add(trow);
TableCell tCell = new TableCell();
tCell.ColumnSpan = 4;
tCell.HorizontalAlign = HorizontalAlign.Center;
trow.Cells.Add(tCell);
tCell.Controls.Add(label);
trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "Servernavn: ";
tCell.Controls.Add(label);
TextBox textbox = new TextBox();
textbox.ID = "txtServerServernavn" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
//trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "Rolle: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtServerRolle" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "IP: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtServerIP" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
//trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "Administrator: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtServerAdministrator" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "PW: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtServerPW" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
//trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "HW model: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtServerHWModel" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "S/N: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtServerSN" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
//trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "Garenti: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtServerGaranti" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "Kommentar: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtServerKommentar" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
}
for (int i = 1; i <= ddlPrinter.SelectedIndex; i++)
{
Label label = new Label();
label.Text = "<h3>Printer " + i + "</h3>";
TableRow trow = new TableRow();
Table1.Rows.Add(trow);
TableCell tCell = new TableCell();
tCell.ColumnSpan = 4;
tCell.HorizontalAlign = HorizontalAlign.Center;
trow.Cells.Add(tCell);
tCell.Controls.Add(label);
trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "HW Model: ";
tCell.Controls.Add(label);
TextBox textbox = new TextBox();
textbox.ID = "txtPrinterHWModel" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
//trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "IP: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtPrinterIP" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
trow = new TableRow();
Table1.Rows.Add(trow);
tCell = new TableCell();
trow.Cells.Add(tCell);
label = new Label();
label.Text = "Kommentar: ";
tCell.Controls.Add(label);
textbox = new TextBox();
textbox.ID = "txtPrinterKommentar" + i;
textbox.Attributes.Add("runat", "server");
tCell = new TableCell();
trow.Cells.Add(tCell);
tCell.Controls.Add(textbox);
}
}
基本上对于我的第一个文本框,它将是&#34; txtServerServernavn&#34; + i其中i == 0。
for (int i = 0; i < antalserver; i++)
{
TextBox test = Request.Params["txtServerServernavn" + i];
serverArr[i, 0] = test.Text;
}
现在request.params是我试过的东西,但希望你能理解:) 基本上,我认为我的问题是,所以我必须把它放在那里而不是阅读它?
修改 好吧认为这里需要更多信息。我的程序中有2个下拉框,它们都会向我的table1添加更多表格单元格和行。 现在,当我更改ddl时,它将进行回发,更改应该有多少可见文本框。然后,当我点击保存时,我希望它被发送到docx但它总是只返回null。 -------------------------间隔------------------------ ---------------------------------------
答案 0 :(得分:0)
好吧,因为我无法得到任何关于这个问题的帮助,所以我决定使用另一种方法来做这件事。
我现在在不同的表中使用Dokumentation.aspx对其进行硬编码,以减少代码隐藏中的代码。我可以隐藏lable和textboxes,但是在我的代码隐藏中需要更多的代码。
在我的代码隐藏中,我只是为服务器列表运行它。
Table[] T = new Table[] { Table1, Table2, Table3, Table4, Table5, Table6, Table7, Table8, Table9, Table10 };
foreach (Table t in T)
{
t.Visible = false;
}
for (int i = 0; i < ddlServer.SelectedIndex; i++)
{
T[i].Visible = true;
}
这也给了我正在寻找的结果,但现在我可以毫无困难地进入我的桌子