首页 新闻 会员 周边

动态添加数据

0
[已关闭问题]

开发中 遇到了一个难题了

就是点一个按钮  动态的在table中(倒数第三行)添加一个一行两列的 ,每个td中放的是文本框   

 

现在点保存的时候  把值存到数据库中,该如何实现~~~

 

尝试了下 前台和后台 都能创建 一行两列   但就是不能保存到数据库中...请哪位仁兄  帮帮忙 ,写个例子。。。

后台:

代码
protected void img_test_Click(object sender, ImageClickEventArgs e)
{
System.Web.UI.HtmlControls.HtmlTableRow tr
= new System.Web.UI.HtmlControls.HtmlTableRow();

System.Web.UI.HtmlControls.HtmlTableCell td
= new System.Web.UI.HtmlControls.HtmlTableCell();

System.Web.UI.HtmlControls.HtmlTableCell td1
= new System.Web.UI.HtmlControls.HtmlTableCell();

td.InnerHtml
= "<input type='text' runat='server' style='width:180px; height:25px;bgcolor=#f3f8fd ;align=center;' >";
td1.InnerHtml
= "<input type='text' runat='server' style='width:300px; height:25px;bgcolor=#f3f8fd ;align=center;' >";

tr.Cells.Add(td);
tr.Cells.Add(td1);
test1.Rows.Insert(test1.Rows.Count
- 2, tr);
}

 

前台:

代码
function attach_add() {
var newtbody
= document.getElementById('theRate');
var newtr
= document.createElement('tr');
var newtd
= document.createElement('td');
var newtd2
= document.createElement('td');
newtd.innerHTML
= '<input type="text" runat="server" style="width:180px; height:25px;bgcolor=#f3f8fd ;align=center;" >';
newtd2.innerHTML
= '<input type="text" runat="server" style="width:300px; height:25px;bgcolor=#f3f8fd ;align=center;" >';
newtr.appendChild(newtd);
newtr.appendChild(newtd2);

var parentEle
= newtbody.rows[newtbody.rows.length - 2].parentNode;


parentEle.insertBefore(newtr, newtbody.rows[newtbody.rows.length
- 2]);
}

 

 

后台 输出数据 ...

代码
string str = string.Empty;

foreach (Control ctl in this.form1.Controls)
{
if (ctl.GetType().Name == "TextBox")
{
TextBox tb
= new TextBox();
tb
= (TextBox)this.form1.FindControl(ctl.ID);

str
= str + tb.Text;
}
}
Response.Write(str);

 

 

数据是输不出来... 

不明白的 可以参考http://www.51.com 这个网站 里面个人设置 兴趣爱好 这一菜单栏 。。。

 

求例子了。。。

like%'远远'%的主页 like%'远远'% | 小虾三级 | 园豆:635
提问于:2010-05-20 17:23
< >
分享
其他回答(1)
0

不知道你试过没有动态的添加服务器控件Textbox,只是觉得这样的话应该还可以的

蝶殇 | 园豆:32 (初学一级) | 2010-05-20 17:45
0

把TextBox tb = new TextBox();
                tb
= (TextBox)this.form1.FindControl(ctl.ID);
改成

HtmlControl tb = new HtmlControl();
                tb
= (HtmlControl)this.form1.FindControl(ctl.ID);

试试

上不了岸的鱼 | 园豆:4613 (老鸟四级) | 2010-05-20 22:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册