Example #1
0
        protected void gvCategoryDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Label   lblCategoryId       = (Label)gvCategoryDetails.Rows[e.RowIndex].FindControl("lblCategoryId");
            TextBox txtEditCategoryName = (TextBox)gvCategoryDetails.Rows[e.RowIndex].FindControl("txtEditCategoryName");
            TextBox txtEditDescription  = (TextBox)gvCategoryDetails.Rows[e.RowIndex].FindControl("txtEditDescription");

            Domain.Category existing = categoryRepo.GetById(Convert.ToInt32(lblCategoryId.Text));
            if (txtEditCategoryName.Text != ("") && txtEditDescription.Text != (""))
            {
                if (existing != null)
                {
                    existing.CategoryName        = txtEditCategoryName.Text;
                    existing.CategoryDescription = txtEditDescription.Text;
                    existing.TenantId            = tenantId;
                    existing.LastUpdatedBy       = "admin";
                    existing.LastUpdationTime    = DateTime.Now;
                }


                categoryRepo.Edit(existing);
                categoryRepo.Save();
                gvCategoryDetails.EditIndex = -1;
                BindData();
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Category Sucessfully Updated');", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Null Filled Not allowed');", true);
            }
            //conn.Open();
            //string cmdstr = "update EmployeeDetails set name=@name,designation=@designation,city=@city,country=@country where empid=@empid";
            //SqlCommand cmd = new SqlCommand(cmdstr, conn);
            //cmd.Parameters.AddWithValue("@empid", lblEditEmpID.Text);
            //cmd.Parameters.AddWithValue("@name", txtEditName.Text);
            //cmd.Parameters.AddWithValue("@designation", txtEditDesignation.Text);
            //cmd.Parameters.AddWithValue("@city", txtEditCity.Text);
            //cmd.Parameters.AddWithValue("@country", txtEditCountry.Text);
            //cmd.ExecuteNonQuery();
            //conn.Close();
            //gvCategoryDetails.EditIndex = -1;
            //BindData();
        }
Example #2
0
        protected void gvCategoryDetails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("ADD"))
                {
                    TextBox txtAddCategoryName = (TextBox)gvCategoryDetails.FooterRow.FindControl("txtAddCategoryName");
                    TextBox txtAddDescription  = (TextBox)gvCategoryDetails.FooterRow.FindControl("txtAddDescription");

                    if (txtAddCategoryName.Text != ("") && txtAddDescription.Text != (""))
                    {
                        Domain.Category category = new Domain.Category()
                        {
                            CategoryDescription = txtAddDescription.Text,
                            CategoryName        = txtAddCategoryName.Text,
                            CreationTime        = DateTime.Now,
                            LastUpdationTime    = DateTime.Now,
                            CreatedBy           = "admin",
                            LastUpdatedBy       = "admin",
                            TenantId            = tenantId,
                        };


                        categoryRepo.Add(category);
                        categoryRepo.Save();
                        BindData();
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Category Sucessfully Inserted');", true);
                        BindData();
                    }

                    else
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Null Filled Not allowed');", true);
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }