protected void Insert(object sender, EventArgs e) { CRUD_SPClient client = new CRUD_SPClient(); var abc = client.DoWork().ToList(); client.Close(); string name = txtName.Text; string country = txtCountry.Text; //string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; //using (SqlConnection con = new SqlConnection(constr)) //{ // using (SqlCommand cmd = new SqlCommand("Resources_CRUD")) // { // cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@Action", "INSERT"); // cmd.Parameters.AddWithValue("@Name", name); // cmd.Parameters.AddWithValue("@Country", country); // cmd.Connection = con; // con.Open(); // cmd.ExecuteNonQuery(); // con.Close(); // } //} client = new CRUD_SPClient(); if (client.Insert(name, country)) { this.BindGrid(client.DoWork().ToList()); } client.Close(); }
protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e) { int ResourcesId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]); string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; //using (SqlConnection con = new SqlConnection(constr)) //{ // using (SqlCommand cmd = new SqlCommand("Resources_CRUD")) // { // cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@Action", "DELETE"); // cmd.Parameters.AddWithValue("@ResourcesId", ResourcesId); // cmd.Connection = con; // con.Open(); // cmd.ExecuteNonQuery(); // con.Close(); // } //} client = new CRUD_SPClient(); if (client.Delete(ResourcesId)) { this.BindGrid(client.DoWork().ToList()); } client.Close(); // this.BindGrid(); }
protected void OnRowCancelingEdit(object sender, EventArgs e) { client = new CRUD_SPClient(); GridView1.EditIndex = -1; this.BindGrid(client.DoWork().ToList()); client.Close(); }
protected void OnRowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; client = new CRUD_SPClient(); this.BindGrid(client.DoWork().ToList()); client.Close(); }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { client = new CRUD_SPClient(); var abc = client.DoWork().ToList();// DoWork() is select query client.Close(); this.BindGrid(abc); } }
protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView1.Rows[e.RowIndex]; int ResourcesId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]); string name = (row.FindControl("txtName") as TextBox).Text; string country = (row.FindControl("txtCountry") as TextBox).Text; string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; //using (SqlConnection con = new SqlConnection(constr)) //{ // using (SqlCommand cmd = new SqlCommand("Resources_CRUD")) // { // cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@Action", "UPDATE"); // cmd.Parameters.AddWithValue("@ResourcesId", ResourcesId); // cmd.Parameters.AddWithValue("@Name", name); // cmd.Parameters.AddWithValue("@Country", country); // cmd.Connection = con; // con.Open(); // cmd.ExecuteNonQuery(); // con.Close(); // } //} client = new CRUD_SPClient(); if (client.Update(ResourcesId, name, country)) { GridView1.EditIndex = -1; this.BindGrid(client.DoWork().ToList()); } client.Close(); // this.BindGrid(); }