gridview下如何实现数据写入,分2种情况,1种是将BoundField一种是TemplateField
不知道我自己写的代码哪里出错了,总是不能写入数据库。点击更新没有反映
我写的代码是
protected void gvw_Drink_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//boundfield
string DrinkName = ((TextBox)gvw_Drink.Rows[e.RowIndex].FindControl("TextBox2")).Text;//boundfield
//string DrinkEng = ((TextBox)gvw_Drink.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
//模版状态
string DrinkEng = gvw_Drink.Rows[e.RowIndex].Cells[2].Text;
string DrinkPri = gvw_Drink.Rows[e.RowIndex].Cells[3].Text;//模版状态
Common com = new Common();
com.Open();
SqlCommand cmd_DrinkUpdate = new SqlCommand("update drink set drink_name='"+DrinkName+"',drink_eng='"+DrinkEng+"',drink_pri='"+DrinkPri+"' where drink_id='"+Convert.ToInt32(this.gvw_Drink.DataKeys[e.RowIndex].Value.ToString())+"'", com.myConnection);
cmd_DrinkUpdate.ExecuteNonQuery();
com.Close();
this.gvw_Drink.EditIndex = -1;
BindToGridView();
}
关于gridview编辑状态下写入数据库的问题