从动态创建的控件将值保存到数据库 [英] Save values to db from dynamically created controls
本文介绍了从动态创建的控件将值保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有一个链接按钮,它将在每次单击时创建文本框和下拉列表.下面是代码
Hello,
I have a link button which will create textboxes and dropdowns on each click. Below is the code
int countTimes;
protected void AddSkills_Click(object sender, EventArgs e)
{
if (ViewState["countTimes"] == null)
{
countTimes = 1;
}
else
{
countTimes = Convert.ToInt32(ViewState["countTimes"]);
}
TextBox txtSkill;
TextBox txtVersion;
TextBox txtLastUsed;
DropDownList ddlExpYears;
DropDownList ddlExpMonths;
for (int i = 0; i < countTimes; i++)
{
txtSkill = new TextBox();
txtVersion = new TextBox();
txtLastUsed = new TextBox();
ddlExpYears = new DropDownList();
ddlExpMonths = new DropDownList();
txtSkill.ID = "txtSkill" + i;
txtVersion.ID = "txtVersion" + i;
txtLastUsed.ID = "txtLastUsed" + i;
ddlExpYears.ID = "ddlExpYears" + i;
ddlExpMonths.ID = "ddlExpMonths" + i;
SkillPlaceHolder.Controls.Add(txtSkill);
SkillPlaceHolder.Controls.Add(txtVersion);
SkillPlaceHolder.Controls.Add(txtLastUsed);
SkillPlaceHolder.Controls.Add(ddlExpYears);
SkillPlaceHolder.Controls.Add(ddlExpMonths);
for (int j = 0; j<= 25; j++)
{
ddlExpYears.Items.Add(new ListItem(j.ToString()));
ddlExpMonths.Items.Add(new ListItem(j.ToString()));
}
}
现在,我想从这些控件中获取值并保存到数据库.怎么做.
请帮助
问候
Now I want to fetch the values from these controls and save to database. How to do.
Kindly help
regards
推荐答案
但是为什么所有这些手工编写的代码呢?为什么不为此使用GridView?看看这里检查一下: ASP.NET 2.0中的可编辑GridView [ ^ ]
祝你好运!
But why all this hand crafted code? Why not use a GridView for this? Have a look here to check it out: Editable GridView in ASP.NET 2.0[^]
Good luck!
这篇关于从动态创建的控件将值保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文