1
我正在使用一個ASP.net項目,並有一個從sql數據庫的數據集作爲數據源的gridview。編輯後得到一個gridview列標題
當我更改gridview中的值時,我想更新數據集,以便我可以使用該數據集再次更新數據庫。
到目前爲止我的說法。
這是我遇到麻煩的部分。我可以獲取選定的行,但不能選擇列名來更新數據集。
myDataSet.Tables[0].Rows[e.RowIndex][?] = "";
RowUpdating事件的完整代碼。
protected void grdViewDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Just get the dataset populated from my database (sql)
DataSet dsOriginal = dbConn.returnSqlDataset(query);
//update the dataset here so that you can update the database again.
foreach (TableCell cell in grdViewDetails.Rows[e.RowIndex].Cells)
{
//set the employeeid so you can update the dataset
if (cell.Controls[0] is TextBox)
{
TextBox textbox = (TextBox)cell.Controls[0];
string value = textbox.Text; //This is just a tester to see if the value is correct
// dsOriginal.Tables[0].Rows[e.RowIndex][?] = value; //Here is the problem, how to get the selected column name
}
else
{
if (cell.Controls[0] is CheckBox)
{
CheckBox chkBoxWeek = (CheckBox)cell.Controls[0];
Boolean checkStatus = chkBoxWeek.Checked; //This is just a tester to see if the value is correct
//dsOriginal.Tables[0].Rows[e.RowIndex][?] = checkStatus; //Here is the problem, how to get the selected column name
}
}
}
//Use the updated dataset to update the database with.
dbConn.udpatCourse(dsOriginal);
}