Пример #1
0
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        String           s  = GridView1.DataKeys[e.RowIndex].Value.ToString();
        CarsInfoEntities db = new CarsInfoEntities();
        Car c = db.Cars.FirstOrDefault(m => m.Model == s);

        db.DeleteObject(c);
        db.SaveChanges();
        ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('Record has been deleted successfully')</script>");

        var result = from t in db.Cars
                     join x in db.Brands on t.BrandId equals x.BrandId
                     select new { x.BrandName, t.Model, t.Costs };

        GridView1.DataSource = result;
        GridView1.DataBind();
    }
Пример #2
0
    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        String           s  = GridView2.DataKeys[e.RowIndex].Value.ToString();
        CarsInfoEntities db = new CarsInfoEntities();
        Brand            br = db.Brands.FirstOrDefault(m => m.BrandName == s);

        db.DeleteObject(br);
        db.SaveChanges();
        ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('Record has been deleted successfully')</script>");

        var data = from a in db.Brands
                   select new { a.BrandName };

        GridView1.Visible    = true;
        GridView2.Visible    = false;
        GridView1.DataSource = data;
        GridView1.DataBind();
    }
Пример #3
0
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        String           s  = GridView1.DataKeys[e.RowIndex].Value.ToString();
        CarsInfoEntities db = new CarsInfoEntities();
        Brand            br = db.Brands.FirstOrDefault(m => m.BrandName == s);

        db.DeleteObject(br);
        try
        {
            db.SaveChanges();
        }
        catch (Exception)
        {
            ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('Cannot delete record. Foreign key constraint violated.')</script>");
        }

        ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('Record has been deleted successfully')</script>");

        var data = from a in db.Brands
                   select new { a.BrandName };

        GridView1.DataSource = data;
        GridView1.DataBind();
    }