1

私はASP.netプロジェクトで作業しており、SQLデータベースのデータセットをデータソースとして持つグリッドビューを持っています。

グリッドビューの値を変更したら、データセットを更新して、そのデータセットを使用してデータベースを再度更新できるようにします。

私がこれまでに持っている声明。

これは私が問題を抱えている部分です。選択した行を取得できますが、データセットを更新するために選択した列名は取得できません。

 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 );


            }
4

1 に答える 1

1

コレクションを繰り返し処理して、GridViewUpdateEventArgs.NewValues更新されたものを見つけることができます。

これは、リンクされた MSDN ドキュメントからわずかに変更されています。

foreach (DictionaryEntry entry in e.NewValues)
{
    string columName = entry.Key;
    string userInput = e.NewValues[entry.Key];
    // Now you can do stuff with this info that meets your logic needs
}

あなたの質問を正しく読んでいれば、ここから必要なものを入手できるはずです。

于 2013-04-15T16:44:16.973 に答える