请问一个使用DataList的问题! 我在DataList模板里添加了一个CheckBox,我想让CheckBox被选中后,相应表格的数据写进另一个数据表里,请问这要怎样去做呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我想让CheckBox被选中后,相应表格的数据写进另一个数据表里==选中就写数据库?这个想法不好,因为用户频繁的点击CheckBox就会导致你的数据库的频繁访问建议外部用按钮确认,一次提交多个复选框选中项的数据 foreach (DataListItem item in DataList1.Items){ CheckBox chk = item.FindControl("CheckBox1") as CheckBox; if (chk != null && chk.Checked) { string id = DataList1.DataKeys[item.ItemIndex].ToString(); //用DataKeys得到主键集合,前提是设置过DataList的DataKeyField属性为表的主键 //下面根据id进行你的数据库操作 }} string id = DataList1.DataKeys[item.ItemIndex].ToString();这里不是很明白,不用id,我也能操作了吧,我想将对应表格里里从一个数据表来的Label里的数据写进另一个数据表。 一般更新和删除都是基于主键的,这个主键来源于DataList的DataKeyField属性 如果你需要找DataList里的Label里的值foreach (DataListItem item in DataList1.Items){ CheckBox chk = item.FindControl("CheckBox1") as CheckBox; if (chk != null && chk.Checked) { string str = (item.FindControl("Label1") as Label).Text; // string id = DataList1.DataKeys[item.ItemIndex].ToString(); //用DataKeys得到主键集合,前提是设置过DataList的DataKeyField属性为表的主键 //下面根据id进行你的数据库操作 }} foreach (DataListItem item in DataList1.Items){ CheckBox chk = item.FindControl("CheckBox1") as CheckBox; if (chk != null && chk.Checked) { string str = ((Label)item.FindControl("Label1")).Text; //你要的标签的值 string sql="";你要执行的语句 执行语句 } 有没有给用户角色分配权限的代码 在数据层调用webservice的问题 OLEDB问题 大家帮看看 关于就地预编译的问题 把flash插入asp.net中,应该怎么做? 大家上午好,实在没分了,帮帮菜鸟吧! .net程序和服务器分别放到两台服务器上 请问 web.config文件应该如何配置? VS2010 Chart控件0值怎么处理? 提供一个大家一起学习的机会asp.net(C#) RegisterStartupScript到底怎么用,什么时候用?查了帮助,没太看懂,哪位给通俗点讲一下,最好有例子 RSS2.0 时间格式的问题 服务器控件不能正常显示图排尿
==
选中就写数据库?这个想法不好,因为用户频繁的点击CheckBox就会导致你的数据库的频繁访问建议外部用按钮确认,一次提交多个复选框选中项的数据
{
CheckBox chk = item.FindControl("CheckBox1") as CheckBox;
if (chk != null && chk.Checked)
{
string id = DataList1.DataKeys[item.ItemIndex].ToString(); //用DataKeys得到主键集合,前提是设置过DataList的DataKeyField属性为表的主键
//下面根据id进行你的数据库操作
}
}
这里不是很明白,不用id,我也能操作了吧,我想将对应表格里里从一个数据表来的Label里的数据写进另一个数据表。
foreach (DataListItem item in DataList1.Items)
{
CheckBox chk = item.FindControl("CheckBox1") as CheckBox;
if (chk != null && chk.Checked)
{
string str = (item.FindControl("Label1") as Label).Text;
// string id = DataList1.DataKeys[item.ItemIndex].ToString(); //用DataKeys得到主键集合,前提是设置过DataList的DataKeyField属性为表的主键
//下面根据id进行你的数据库操作
}
}
{
CheckBox chk = item.FindControl("CheckBox1") as CheckBox;
if (chk != null && chk.Checked)
{
string str = ((Label)item.FindControl("Label1")).Text; //你要的标签的值
string sql="";你要执行的语句
执行语句
}