注册 登录
编程论坛 ASP.NET技术论坛

Gridview 控件有关问题!(急!急!)

bavfhpdn66 发布于 2007-05-13 01:42, 1065 次点击

因为在数据库中审核和未审核的信息用数字表示(“0”表示未审核,“1”表示已审核),但在显示时不能显示“0”或者“1”,所以必须把其转换成相应的 汉字。想实现代码如下:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[4].Text == "0")
{
e.Row.Cells[4].Text = "未审核";
}
else
{
e.Row.Cells[4].Text = "<font color=red>已审核</font>";
}
((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗?')");
}
}

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string id=this.GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
SqlCommand scd = new SqlCommand("select Auditing from tb_OldTruck where id=" + id, strcon);
string Auditing = Convert.ToString(scd.ExecuteScalar());
if (Auditing == "0")
{
Auditing = "1";
}
else
{
Auditing = "0";
}
scd.CommandText = "update tb_OldTruck set Auditing=" + Auditing + " where id=" + id;
scd.ExecuteNonQuery();
this.bind();
strcon.Close();
}
为什么当我填完一个注册用户信息提交注册成功,但还没审核,而此时会显示“审核”状态?
好郁闷啊

10 回复
#2
shenba2007-05-13 07:40
可以啊
你的 e.Cell[4]是模板列吗 还是普通的绑定列 模板列的话 需要转化下
#3
冰镇柠檬汁儿2007-05-13 12:20

楼主,是你的程序有问题,是个逻辑问题,你在添加到数据库的时候,应该是审核的值,即非零的值,楼主看看是不是

#4
bavfhpdn662007-05-13 13:55

是不是把if (Auditing == "0")
这句中的"0"改为"1"

我改了
不 过还是不 行!

#5
川流不息2007-05-13 21:36
你在查詢SQL語句的時候就可以轉了,不必要在程序中轉:
SELECT CASE 字段名 WHEN '0' THEN '未審核' WHEN '1' THEN '已審核' END AS 別名 FROM TABLENAME
#6
bavfhpdn662007-05-13 22:19


我弄好了

#7
sss3332007-05-16 15:00
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int uto = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "列名"));
if (uto == 0)
{
e.Row.Cells[4].Text = "未审核";
}
else
{
e.Row.Cells[4].Text = "已审核";
}
}
}
试试这样行不行

[此贴子已经被作者于2007-5-16 15:01:56编辑过]

#8
sss3332007-05-16 15:01
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int uto = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "列名"));
if (uto == 0)
{
e.Row.Cells[4].Text = "未审核";
}
else
{
e.Row.Cells[4].Text = "已审核";
}
}
}
刚才写错了
#9
young53352007-05-16 17:07
恐怖,里竟然还手工绑定。那就不知道为什么用2.0而不用1.0?
#10
tel19822007-05-17 08:29
我也实现过这样的功能,不过不是这样实现的,不过解决了就好。
#11
bavfhpdn662007-06-13 16:42

谢谢!

1