我有一個簡單的gridview。 將tableData綁定到gridview的SqlDataSource。GridView:如何在行更新中每次增加一個單元格的值?
行更新我試圖增加一個單元格(int類型)的值。 這裏是我的代碼,但不幹活G:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
string str = ((TextBox)(row.Cells[8].Controls[0])).Text;
int conv = Convert.ToInt32(str);
int set = conv + 1;
string conn = "conn string";
string sqlQuery = "UPDATE TableName SET Total [email protected]";
using (SqlConnection dataConnection = new SqlConnection(conn))
{
using (SqlCommand dataCommand = new SqlCommand(sqlQuery, dataConnection))
{
dataCommand.Parameters.AddWithValue("Total", set);
dataConnection.Open();
dataCommand.ExecuteNonQuery();
dataConnection.Close();
}
}
}
我不知道爲什麼不工作,我需要一個在當前編輯行的細胞增加。
感謝
您已經聲明和初始化'conv'卻無處使用。什麼是'stra',因爲它沒有在你的代碼中聲明或初始化? – 2012-04-09 19:06:20
而且我的代碼是不工作的東西是錯誤的..但我不知道在哪裏,因爲我沒有得到任何錯誤,但沒有更新 – 2012-04-09 19:13:01