Asp的代码 ID 指定问题

来源:百度知道 编辑:UC知道 时间:2024/05/25 07:30:10
源代码
if (e.CommandName == "update1") //按钮判断
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
if (GridView1.Rows[id].Cells[5].Text == "已审核")
{
string str_xg = "update myweb set usersh='2' where id=" + GridView1.Rows[id].Cells[0].Text;
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["sqlconn"].ToString());
conn.Open();
SqlCommand cmd = new SqlCommand(str_xg, conn);
cmd.ExecuteNonQuery();
conn.Close();
cmd.Clone();

GridView1.Rows[id].Cells[5].Text = "拒绝";

}
else
{
string str_xg = "update myweb set usersh='1'where id=" + GridView1.Rows[id].Cells[0].Text;

GridView1.Rows[id].Cells[0].Text 是字符串
你数据库里的id一般都是int型,类型不同当然会报错
可以用类型转换函数把GridView1.Rows[id].Cells[0].Text转成int型,应该就好了
另外看这代码应该是asp.net的吧

你的cells[0]是个什么控件, 文本框, 还是复选框?,还是label

GridView1.Rows[id].Cells[0].Text 是字符串
你数据库里的id一般都是int型,类型不同当然会报错
可以用类型转换函数把GridView1.Rows[id].Cells[0].Text转成int型,应该就好了
另外看这代码应该是asp.net的