예제 #1
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     using (Arenda_bookContext db = new Arenda_bookContext())
     {
         Arenda_book app = new Arenda_book()
         {
             id_book = int.Parse(DropDownList1.Text),
             id_fio  = int.Parse(DropDownList2.Text),
             Data_1  = DateTime.Parse(TextBox1.Text),
             Data_2  = DateTime.Parse(TextBox2.Text)
         };
         db.Arenda_book.Add(app);
         db.SaveChanges();
     }
     Response.Redirect("WebForm1.aspx");
 }
예제 #2
0
 protected void Button3_Click(object sender, EventArgs e)
 {
     using (Arenda_bookContext db = new Arenda_bookContext())
     {
         foreach (GridViewRow rowInGrid in GridView1.Rows)
         {
             CheckBox checkBox = (CheckBox)rowInGrid.FindControl("CheckBox1");
             if (checkBox != null && checkBox.Checked)
             {
                 int         id    = int.Parse(GridView1.Rows[rowInGrid.RowIndex].Cells[1].Text);
                 Arenda_book delId = db.Arenda_book.Where(s => s.Id == id).FirstOrDefault();
                 if (delId != null)
                 {
                     db.Arenda_book.Remove(delId);
                     db.SaveChanges();
                 }
             }
         }
         Response.Redirect("WebForm1.aspx");
     }
 }