动态生成文本框 [英] Dynamically generate Textboxes
本文介绍了动态生成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
海,
我想在下拉列表中选择一个项目时动态生成文本框..有人知道吗请让我知道
Hai,
I want to generate textboxes dynamically when i select a item in dropdownlist..can anybody knows please let me know
推荐答案
代码创建的标签数量与用户拥有的标签控件一样多从下拉列表中选择.控件的容器是一个名为Placeholder1
的PlaceHolder Web服务器控件.
The code creates as many label controls as the user has selected from the drop-down list. The container for the controls is a PlaceHolder Web server control named Placeholder1
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
DropDownList DropDownList1 = new DropDownList();
PlaceHolder PlaceHolder1 = new PlaceHolder();
// Get the number of labels to create.
int numlabels = System.Convert.ToInt32(DropDownList1.SelectedItem.Text);
for (int i=1; i<=numlabels; i++)
{
Label myLabel = new Label();
// Set the label's Text and ID properties.
myLabel.Text = "Label" + i.ToString();
myLabel.ID = "Label" + i.ToString();
PlaceHolder1.Controls.Add(myLabel);
// Add a spacer in the form of an HTML <br /> element.
PlaceHolder1.Controls.Add(new LiteralControl("<br />"));
}
}
私有无效DropDownList1_SelectedIndexChanged(对象发送方,EventArgs e)
{
TextBox txtName = new TextBox();
this.controls.Add(txtName);
}
private void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox txtName = new TextBox();
this.controls.Add(txtName);
}
TextBox txtName = new TextBox();
//在页面上添加以下代码
this.controls.Add(txtName);
TextBox txtName = new TextBox();
//Add the following code on the Page
this.controls.Add(txtName);
这篇关于动态生成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文