gridview编辑失败 模板项中按钮中commandName也写update了
gridview编辑失败 模板项中按钮中commandName也写update了我实在不知道是怎吗回事
总是提示:
[b]异常详细信息: [/b][font=Arial]System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: index[/font]
[font=Arial][/font]
[font=Arial]真无语了,哪位大哥大姐帮小弟解决一下 不胜感激!!![em01] [em01] [em01] [em01] [em01] [em01] [/font]
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string sqlcomm = "update UF_OWNERCOMM(UF_OWNERCOMM_NAME) values ('" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).ToString() + "') where UF_OWNERCOMM_ID = '"+GridView1.DataKeys[e.RowIndex].Value.ToString()+"'";
SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
myconn.Open();
int i = new SqlCommand(sqlcomm, myconn).ExecuteNonQuery(); ;
if (i>0)
{
Response.Write("<script>alert('更新成功')</script>");
}
else
{
Response.Write("<script>alert('更新失败')</script>");
}
myconn.Close();
GridView1.EditIndex = -1;
datebing();
}
加上text啊…… 还是不行啊[em04] [em04] [em04] [em04] [em04]
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string sqlcomm = "update UF_OWNERCOMM(UF_OWNERCOMM_NAME) values ('" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString() + "') where UF_OWNERCOMM_ID = '"+GridView1.DataKeys[e.RowIndex].Value.ToString()+"'";
SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
myconn.Open();
int i = new SqlCommand(sqlcomm, myconn).ExecuteNonQuery(); ;
if (i>0)
{
Response.Write("<script>alert('更新成功')</script>");
}
else
{
Response.Write("<script>alert('更新失败')</script>");
}
myconn.Close();
GridView1.EditIndex = -1;
datebing();
} 我没有用过GridView1的哦 呵呵 我都是用Repeater
应该是GridView1.Rows[e.RowIndex].Cells[1].Controls[0]和GridView1.DataKeys[e.RowIndex].Value这句中的问题 你打断点看看的噻 应该是其中某一个位置取出来是一个NULL值才报的这个错得 如果不行的话,你把GridView1.Rows[e.RowIndex].Cells[1].Controls[0]和GridView1.DataKeys[e.RowIndex].Value先单独写出来。
string a=GridView1.DataKeys[e.RowIndex].Value
………………
然后在sql语句中用你定义的变量(a……), 效果一样 为什么我一做就遇到 索引超出范围 关键字index
页:
[1]
