datagrid编辑,取消,删除,修改

来源:互联网 发布:教绘画软件下载 编辑:程序博客网 时间:2024/04/29 19:37

  protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
    {
        DataGrid1.EditItemIndex = e.Item.ItemIndex;
        bond();
    }
    protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e)
    {
        DataGrid1.EditItemIndex = -1;
        bond();
    }

    protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
    {
        string id = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
        string name = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
        string aaa = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
        string sql = "update Employees set LastName='" + name + "', FirstName='" + aaa + "' where EmployeeID=id";
        SqlConnection myconn=new SqlConnection("server=(local);database=Northwind;uid=sa;pwd=");
        SqlCommand comm = new SqlCommand(sql, myconn);
        myconn.Open();

        comm.ExecuteNonQuery();
        myconn.Close();
    }

原创粉丝点击