gridview 编辑更新代码更新不了值是怎么回事/
点击更新时候,textbox值不变protectedvoidgvCategoryList_RowUpdating(objectsender,GridViewUpdateE...
点击更新时候,textbox值不变
protected void gvCategoryList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int ID = Convert.ToInt32(gvCategoryList.DataKeys[e.RowIndex].Value.ToString());
GridViewRow myrow = gvCategoryList.Rows[e.RowIndex];
string _Name = ((TextBox)(gvCategoryList.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
string _Number = ((TextBox)(gvCategoryList.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
ad.ExecuteSqlWrite("Update qq set Name='" + _Name + "',Number='" + _Number+ "' where QQID=" + ID);
gvCategoryList.EditIndex = -1;
databind();
} 展开
protected void gvCategoryList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int ID = Convert.ToInt32(gvCategoryList.DataKeys[e.RowIndex].Value.ToString());
GridViewRow myrow = gvCategoryList.Rows[e.RowIndex];
string _Name = ((TextBox)(gvCategoryList.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
string _Number = ((TextBox)(gvCategoryList.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
ad.ExecuteSqlWrite("Update qq set Name='" + _Name + "',Number='" + _Number+ "' where QQID=" + ID);
gvCategoryList.EditIndex = -1;
databind();
} 展开
展开全部
SqlConnection con = DBClass.Getcon();
try
{
con.Open();
string sql = "update Item set title='"+((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim()+"'where Itemid='"+GridView1.DataKeys[e.RowIndex].Value.ToString()+"' ";
SqlCommand cmd = new SqlCommand(sql,con);
cmd.ExecuteNonQuery();
this.GridView1.EditIndex = -1;
bind();
}
catch (Exception ex)
{
this.Response.Write(ex.Message);
}
finally
{
con.Close();
}
try
{
con.Open();
string sql = "update Item set title='"+((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim()+"'where Itemid='"+GridView1.DataKeys[e.RowIndex].Value.ToString()+"' ";
SqlCommand cmd = new SqlCommand(sql,con);
cmd.ExecuteNonQuery();
this.GridView1.EditIndex = -1;
bind();
}
catch (Exception ex)
{
this.Response.Write(ex.Message);
}
finally
{
con.Close();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询