0

削除メソッドを実装し、削除操作のパラメーターを渡そうとしています。私はsqldatasourceを使用しています。グリッドビューに ID の列がないため、ID の値を取得して削除パラメータとして設定するにはどうすればよいですか?

4

2 に答える 2

0

ID は、データソースにある限り、GridView に列を必要としません。これは、手順を説明する簡単な GridView チュートリアルです...

http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx

彼らの RowDeleting ハンドラー...

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
  customer.Delete(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
  FillCustomerInGrid();
}
于 2010-05-07T17:42:48.593 に答える
0

gridview の OnRowDeleting イベントを処理するメソッドを設定し、そこで削除をキャンセルし、独自のロジックを実装して削除を実行できます (つまり、id 以外のフィールドに基づいて削除します)。

<asp:GridView OnRowDeleting="gridview_rowdeleting" />


protected void gridview_rowdeleting(Object sender, GridViewDeleteEventArgs e)
    {
    e.Cancel = true;
        // logic for performing delete here...e.Rows returns the collection of deleted rows so you can access whatever values you need...e.Rows[0].Cells[0] gives the value in the first column for the first deleted row for example
    }
于 2010-05-07T17:44:25.657 に答える