void Datagrid1_Update(Object sender, DataGridCommandEventArgs e)
{
// get the ID of the record to update
int empID = (int)Datagrid1.DataKeys[e.Item.ItemIndex];
// get the references to the edit controls
DropDownList title = (DropDownList)e.Item.FindControl("EditTitle");
TextBox lastName = (TextBox)e.Item.FindControl("EditLastName");
TextBox firstName = (TextBox)e.Item.FindControl("EditFirstName");
TextBox city = (TextBox)e.Item.Cells[5].Controls[0];
// create the connection and the UPDATE command
string connString = "server=(local);database=Northwind;uid=sa;pwd=;";
string sql = @"UPDATE Employees SET TitleOfCourtesy = @TitleOfCourtesy,
LastName = @LastName, FirstName = @FirstName, City = @City WHERE EmployeeID = @EmployeeID";
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(sql, conn);
// stop the editing and rebind the grid
Datagrid1.EditItemIndex = -1;
BindGrid();
}
void Datagrid1_Delete(Object sender, DataGridCommandEventArgs e)
{
// get the ID of the record to update
int empID = (int)Datagrid1.DataKeys[e.Item.ItemIndex];
// create the connection and the DELETE command
string connString = "server=(local);database=Northwind;uid=sa;pwd=;";
string sql = @"DELETE FROM Employees WHERE EmployeeID = " + empID.ToString();
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(sql, conn);