我改变了我的问题,因为它可能不被理解。也对不起我的英语...
动态创建将它们放入数组的文本框。
我的一段代码:
public partial class NewArticleForm : System.Web.UI.Page
{
private Label[] lblName;
private TextBox[] txtName;
private Label[] lblSurname;
private TextBox[] txtSurname;
private PlaceHolder PlaceHolder1;
public int NumberOfOtherAuthors()
{
Int32 index = Convert.ToInt32(NumberList.SelectedValue);
return index;
}
public void dataofOtherAuthor()
{
int authors;
int i = 0;
int j=1
authors = NumberOfOtherAuthors();
lblName = new Label[authors];
txtName = new TextBox[authors];
lblSurname = new Label[authors];
txtSurname = new TextBox[authors];
PlaceHolder1 = new PlaceHolder();
for (i = 0; i < authors; i++)
{
Label authorInformation = new Label();
authorInformation.Text = "Information for Author " + j.ToString() + " :";
lblName[i] = new Label();
lblName[i].Text = "Name:";
txtName[i] = new TextBox();
lblSurname[i] = new Label();
lblSurname[i].Text = "Surname:";
txtSurname[i] = new TextBox();
PlaceHolder1.Controls.Add(authorInformation);
PlaceHolder1.Controls.Add(lblName[i]);
PlaceHolder1.Controls.Add(txtName[i]);
PlaceHolder1.Controls.Add(lblSurname[i]);
PlaceHolder1.Controls.Add(txtSurname[i]);
// Add a spacer in the form of an HTML <BR> element.
Panel1.Controls.Add(PlaceHolder1);
j++; } }
protected void NumberList_SelectedIndexChanged(object sender, EventArgs e)
{
dataofOtherAuthor();
}
private void UploadForm()
{
int numberOfOtherAuthors = NumberOfOtherAuthors();
int i=0;
for (i = 0; i < numberOfOtherAuthors; i++)
{
Label1.Text = txtName[i].Text;
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
UploadForm();
}
}
如何获得文本框的值?具体来说,我想在数据库中传递数据。如果我得到值,标签是一个测试。
谢谢!!!