大家帮我看看这个是哪里的问题

wylovemzc 2009-02-03 09:34:09
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();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (SurveyStatus2 == "有效")
{
//GridView1中显示字段的位置,假如在第5列就用e.Row.Cells[4].Text
e.Row.Cells[6].Text = "<a href=CategoryInfoInfo.aspx?SurveyID=" + SurveyID + ">有效</a>";
}
if (SurveyStatus2 == "完成")
{
e.Row.Cells[6].Text = "完成";
}
if (SurveyStatus2 == "失败")
{
e.Row.Cells[6].Text = "失败";
}
if (SurveyStatus2 == "进行中")
{
e.Row.Cells[6].Text = "进行中";
}
}
}

现在问题出在,绑定完数据后,第2条数据把第1条的e.Row.Cells[6].Text的值覆盖了
...全文
115 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
scjtswj 2009-02-03
  • 打赏
  • 举报
回复
直接在GridView1里改



<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Eval("SurveyStatus").ToString() == "有效" ? "<a href=CategoryInfoInfo.aspx?SurveyID=" + Eval("SurveyID").ToString() + ">有效 </a>" : Eval("SurveyStatus").ToString()%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
..其他列
</asp:GridView>
kke_007 2009-02-03
  • 打赏
  • 举报
回复
if (SurveyStatus2 == "有效")
{
//GridView1中显示字段的位置,假如在第5列就用e.Row.Cells[4].Text
e.Row.Cells[6].Text = " <a href=CategoryInfoInfo.aspx?SurveyID=" + SurveyID + ">有效 </a>";
return;
}
if (SurveyStatus2 == "完成")
{
e.Row.Cells[6].Text = "完成";
return;
}
if (SurveyStatus2 == "失败")
{
e.Row.Cells[6].Text = "失败";
return;
}
if (SurveyStatus2 == "进行中")
{
e.Row.Cells[6].Text = "进行中";
return;
}
阿云ivan 2009-02-03
  • 打赏
  • 举报
回复
改成
if(...)
{}
else if(...)
{}
else if(...)
{}
hncz_zhoumin 2009-02-03
  • 打赏
  • 举报
回复
调试....
scjtswj 2009-02-03
  • 打赏
  • 举报
回复
你绑定那段代码有问题的,在WHILE循环里面绑定GridView1 ,有几条数据就绑定几次。。
string sql = "select SurveyID,SurveyDate,SurveyProject,SurveyCPI,SurveyLength,SurveyMemo,SurveyStatus from survey";
con = new SqlConnection(connstr);
con.Open();
SqlCommand com = new SqlCommand(sql, con);
GridView1.DataSource = com.ExecuteReader();
GridView1.DataBind();

后台这样绑定,前台用我4楼的方法
wylovemzc 2009-02-03
  • 打赏
  • 举报
回复
楼上的几位大哥的办法我都试了,还是不行啊。。。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧