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

有关GRIDVIW控件中分页后选折CHECKBOX控件问题
<script type="text/javascript">
  function selectAll(obj)
  {  
  //alert(document.getElementById("GridView1").rows.length);
  var state;
  if(obj.checked==true)
  state = true;
  else
  state = false;
  for (var i =2; i < document.getElementById("GridView1").rows.length+4; i++) 
  {  
  if(i>=10)
  document.getElementById("GridView1_ctl"+i+"_CheckBox1").checked=state;
  else
  document.getElementById("GridView1_ctl0"+i+"_CheckBox1").checked=state;
  }  
  }

  </script>

分页后为什么选完后上传被选不执行呢?
就是选中了但是上传他怎么是没选中的状态为什么

  int intCount = this.GridView1.Rows.Count;
  for (int i = 0; i < intCount; i++)
  {
  CheckBox CheckBox1 = this.GridView1.Rows[i].Cells[5].FindControl("CheckBox1") as CheckBox;
  if (CheckBox1.Checked)
  {
  //string title =this.GridView1.Rows[i].Cells[1].Text;
  string title = CheckBox1.Checked.ToString();
  // string id = GridView1.Rows[i].Cells[0].Text;
  Label id = (Label) GridView1.Rows[i].Cells[1].FindControl("label1");//
  string sqlcontent = "UPDATE Tips SET Release ='" + title + "' where Title='" + id.Text +"'";
  try
  {
  SqlCommand cmd = new SqlCommand(sqlcontent,OffFactory.db.WebCreatecon());
  SqlCommand cmd1 = new SqlCommand(sqlcontent, OffFactory.db.GadgetCreatecon());
  cmd.ExecuteNonQuery();
  cmd1.ExecuteNonQuery();
  }
  catch
  {
  Response.Write("<script language='javascript'>alert('操作失败!')</script>");
  Response.Write("<script language='javascript'>window.location.href='Default.aspx'</script>");
  }
  }
  else
  {
  //string title = CheckBox1.Checked.ToString();
  string title = CheckBox1.Checked.ToString();
  //string id = GridView1.Rows[i].Cells[0].Text;
  Label id = (Label)GridView1.Rows[i].Cells[1].FindControl("label1");
  string sid = id.Text;
  string sqlcontent = "UPDATE Tips SET Release ='" + title + "' where Title='" + sid + "'";
  try
  {
  SqlCommand cmd = new SqlCommand(sqlcontent, OffFactory.db.WebCreatecon());
  SqlCommand cmd1 = new SqlCommand(sqlcontent, OffFactory.db.GadgetCreatecon());
  cmd.ExecuteNonQuery();
  cmd1.ExecuteNonQuery();
  }
  catch 
  {
  Response.Write("<script language='javascript'>alert('操作失败!')</script>");
  Response.Write("<script language='javascript'>window.location.href='Default.aspx'</script>");
  }