日期:2014-05-18  浏览次数:20427 次

Repeater控件中check模板列的问题
如题,我有个Repeater控件,里面有个check模板列,在Repeater控件外面有个更新按钮,现在,我是想:把那些有选中checkbox的全部一次更新,然后只弹出一个提示更新成功的对话框,现在情况是更新数据是可以实现,但会出现有选中的checkbox每次弹出1个对话框,要点下,感觉这样很麻烦,能帮我看下嘛(应该是遍历时候,那句提示的代码没有放在正确位置),谢了
 protected void Button3_Click(object sender, EventArgs e)
  {
  foreach (RepeaterItem rp1 in Repeater1.Items)
  {
  System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)rp1.FindControl("CheckBox1");
  if (cb.Checked == true)
  {
  HiddenField hf1 = (HiddenField)rp.FindControl("txtId");
  DataTable dt = getdt("select * from student where id=" + Convert.ToInt32(hf1.Value));
  if (dt.Rows.Count > 0)
  {
  try
  {
  for (int i = 0; i < dt.Rows.Count; i++)
  {
  ......
  }
  Response.Write("<script language=javascript>alert('修改成功!')</script>"); 
  }
  catch (SqlException ex)
  {
  Response.Write(ex.Message);
  }
  }
  }  
  }
  }

------解决方案--------------------
这个代码比较乱,不好改。

干脆你就在页面里放一个Literal控件,然后把你原来输出脚本的这句,改成:
if(Literal1.Text.Length==0)
Literal1.Text="<script language=javascript>alert('修改成功!')</script>";
------解决方案--------------------
不会吧,你有试过?这句的意思你明白吗?无论怎么执行,Literal1.Text的值都只有一个alert的脚本,怎么会弹出多次呢?