asp.net 动态生成控件并获取其值
摘要:复制代码代码如下://动态生成三个控件protectedvoidButton1_Click(objectsender,EventArgse)...
复制代码 代码如下:
//动态生成三个控件
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 3; i++)
{
TextBox t = new TextBox();
t.ID = string.Format("newTextBox{0}",i);
Panel1.Controls.Add(t);
}
ListControlsInPanel();
}
复制代码 代码如下:
//获取动态生成的控件的值
protected void Button3_Click(object sender, EventArgs e)
{
string str="";
string[] ak = Request.Form.AllKeys;
for (int i = 0; i < Request.Form.Count; i++)
{
//只筛选出动态生成的三个控件的值
if(ak[i].IndexOf ("new")>-1)
str += string.Format("<li>{0}</li><br>",Request .Form [i]);
}
Label1.Text = str;
}
//这里新生成的控件的ID命名使用new开头,同时应保证页面没有控件的ID包含new。
【asp.net 动态生成控件并获取其值】相关文章:
★ Asp.Net(C#)自动执行计划任务的程序实例分析分享
★ asp.net datalist绑定数据后可以上移下移实现示例