示例#1
0
        protected void contactODS_Updated(object sender, ObjectDataSourceStatusEventArgs e)
        {
            int idContact = int.Parse(Request.QueryString["id"]);

            using (EntityExeEntities context = new EntityExeEntities())
            {
                try
                {
                    Contact_Service contact_Service = context.Contact_Service.FirstOrDefault(cs => cs.ContactsId == idContact);
                    if (contact_Service != null)
                    {
                        context.Contact_Service.Remove(contact_Service);
                    }

                    //Ajouter les données dans la table contact_service
                    setRowDataForGridCS();
                    DataTable csTable = (DataTable)ViewState["currentTableService"];

                    for (int i = 0; i < csTable.Rows.Count; i++)
                    {
                        Contact_Service cs = new Contact_Service();
                        cs.ContactsId     = idContact;
                        cs.Tag_servicesId = Int32.Parse(csTable.Rows[i][0].ToString());
                        cs.ContactTypeId  = Int32.Parse(csTable.Rows[i][1].ToString());
                        context.Contact_Service.Add(cs);
                    }

                    context.SaveChanges();

                    GridView         gv  = (GridView)contactDV.FindControl("serviceGV");
                    ObjectDataSource ods = (ObjectDataSource)contactDV.FindControl("serviceODS");



                    //gv.DataSource = csTable;
                    //gv.DataBind();
                }
                catch (Exception ex)
                { }
            }
        }
示例#2
0
        protected void updateBtn_Click(object sender, EventArgs e)
        {
            int idContact = int.Parse(Request.QueryString["id"]);



            using (EntityExeEntities context = new EntityExeEntities())
            {
                try
                {
                    ObjectDataSource1.UpdateParameters["firstName"].DefaultValue = ((TextBox)contactDV.FindControl("firstNameETB")).Text;

                    ObjectDataSource1.UpdateParameters["Original_id"].DefaultValue = Request.QueryString["id"];
                    ObjectDataSource1.Update();

                    Contact_Service contact_Service = context.Contact_Service.FirstOrDefault(cs => cs.ContactsId == idContact);
                    if (contact_Service != null)
                    {
                        context.Contact_Service.Remove(contact_Service);
                    }

                    //Ajouter les données dans la table contact_service
                    setRowDataForGridCS();
                    DataTable csTable = (DataTable)ViewState["currentTableService"];

                    for (int i = 0; i < csTable.Rows.Count; i++)
                    {
                        Contact_Service cs = new Contact_Service();
                        cs.ContactsId     = idContact;
                        cs.Tag_servicesId = Int32.Parse(csTable.Rows[i][0].ToString());
                        cs.ContactTypeId  = Int32.Parse(csTable.Rows[i][1].ToString());
                        context.Contact_Service.Add(cs);
                    }

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }
        }