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

问个GridView改变列值的问题
protected void Page_Load(object sender, EventArgs e)
  {
  try
  {
  string sql = "select SurveyID,SurveyDate,SurveyProject,SurveyCPI,SurveyLength,SurveyMemo,SurveyStatus from survey";
  con = new SqlConnection(connstr);
  con.Open();
  SqlCommand com = new SqlCommand(sql, con);
  SqlDataReader read = com.ExecuteReader();
  while (read.Read())
  {
  SurveyID = read["SurveyID"].ToString();
  SurveyDate = read["SurveyDate"].ToString();
  SurveyProject = read["SurveyProject"].ToString();
  SurveyCPI = read["SurveyCPI"].ToString();
  SurveyLength = read["SurveyLength"].ToString();
  SurveyMemo = read["SurveyMemo"].ToString();
  SurveyStatus = read["SurveyStatus"].ToString();
  string sql1 = "select * from surveylog where Username='wangyi1687' and SurveyID='" + SurveyID + "'";
  con = new SqlConnection(connstr);
  con.Open();
  SqlCommand com1 = new SqlCommand(sql1, con);
  SqlDataReader reader = com1.ExecuteReader();
  if (reader.Read())
  {
  SurveyStatus2 = reader["SurveyStatus"].ToString();  
  con = new SqlConnection(connstr);
  string sql2 = "select * from survey where SurveyID='" + SurveyID + "'";
  //创建SqlDataAdapter对象,调用sql
  SqlDataAdapter myadapter = new SqlDataAdapter(sql2, con);
  //创建并填充DataSet
  myadapter.Fill(ds);
  GridView1.DataSource = ds;
  GridView1.DataBind();
  con.Close();
  }
  }
  }
  catch (Exception ex)
  {
  ex.ToString();
  }
  }
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  if (SurveyStatus2 == "有效")
  {
  e.Row.Cells[6].Text = "<a href=CategoryInfoInfo.aspx?SurveyID=" + SurveyID + ">有效</a>";
  }
  else
  {
  e.Row.Cells[6].Text = SurveyStatus2;
  }
  }
  }

现在的问题是,如果判断出来的SurveyStatus2是有效,那么就把另外的那条数据给覆盖了,而且RowDataBound事件里执行了2次if (SurveyStatus2 == "有效")


------解决方案--------------------
你现在的数据是否有两天记录?

GridView1_RowDataBound事件是每次绑定行的时候都会触发的
------解决方案--------------------
页面装载事件表明,每回调一次,就重新绑定业次,如果你在表格上进行操作,那肯定要回调一次再执行对应的事件一次,加起来应是二次
------解决方案--------------------
是不是要调整这个列的宽度啊。
GridView1_RowDataBound 每行会进一次。
------解决方案--------------------
那么就把另外的那条数据给覆盖了
---------------------------------------
另外的那條數據是什么數據?聽不明白。
------解决方案--------------------
支持一下