protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; GridView1.EditIndex = rowIndex; } else if (e.CommandName == "DeleteRow") { if (ViewState["IfSearch"] == null) { CustomerDataAcessLayer.DeleteCustomer(Convert.ToInt32(e.CommandArgument)); con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select *from dbo.CUSTOMERS"; con.Close(); DataTable dt1 = new DataTable(); SqlDataAdapter dad = new SqlDataAdapter(cmd); dad.Fill(dt1); ViewState["dataTBL"] = dt1; GridView1.EditIndex = -1; GridView1.DataSource = dt1; GridView1.DataBind(); int count = dt1.Rows.Count; EnterToGrid(count); } else { CustomerDataAcessLayer.DeleteCustomer(Convert.ToInt32(e.CommandArgument)); con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = " SELECT * FROM [dbo].[CUSTOMERS] where Full_Name like '%'+@Full_Name+'%' OR Company like '%'+@Full_Name+'%'"; cmd.Connection = con; cmd.Parameters.AddWithValue("Full_Name", ViewState["IfSearch"].ToString()); con.Close(); DataTable dt1 = new DataTable(); SqlDataAdapter dad = new SqlDataAdapter(cmd); dad.Fill(dt1); ViewState["dataTBL"] = dt1; GridView1.EditIndex = -1; GridView1.DataSource = dt1; GridView1.DataBind(); int count = dt1.Rows.Count; EnterToGrid(count); } } else if (e.CommandName == "CancelRow") { GridView1.EditIndex = -1; } else if (e.CommandName == "UpdateRow") { if (ViewState["IfSearch"] == null) { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; int rollno = Convert.ToInt32(e.CommandArgument); string Full_Name = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox1")).Text; string Country = ((DropDownList)GridView1.Rows[rowIndex].FindControl("DropDownList1")).SelectedValue; string Company = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox2")).Text; string Email = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox3")).Text; CustomerDataAcessLayer.UpdateCustomer(rollno, Full_Name, Company, Country, Email); con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select *from dbo.CUSTOMERS"; con.Close(); DataTable dt1 = new DataTable(); SqlDataAdapter dad = new SqlDataAdapter(cmd); dad.Fill(dt1); ViewState["dataTBL"] = dt1; GridView1.EditIndex = -1; } else { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; int rollno = Convert.ToInt32(e.CommandArgument); string Full_Name = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox1")).Text; string Country = ((DropDownList)GridView1.Rows[rowIndex].FindControl("DropDownList1")).SelectedValue; string Company = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox2")).Text; string Email = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox3")).Text; CustomerDataAcessLayer.UpdateCustomer(rollno, Full_Name, Company, Country, Email); con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM [dbo].[CUSTOMERS] where Full_Name like '%'+@Full_Name+'%' OR Company like '%'+@Full_Name+'%'"; cmd.Connection = con; cmd.Parameters.AddWithValue("Full_Name", ViewState["IfSearch"].ToString()); con.Close(); DataTable dt1 = new DataTable(); SqlDataAdapter dad = new SqlDataAdapter(cmd); dad.Fill(dt1); ViewState["dataTBL"] = dt1; GridView1.EditIndex = -1; } } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; GridView1.EditIndex = rowIndex; string stmt = "SELECT COUNT(*) FROM dbo.CUSTOMERS"; int count = 0; using (SqlCommand cmdCount = new SqlCommand(stmt, con)) { con.Open(); count = (int)cmdCount.ExecuteScalar(); con.Close(); } EnterToGrid(count); } else if (e.CommandName == "DeleteRow") { CustomerDataAcessLayer.DeleteCustomer(Convert.ToInt32(e.CommandArgument)); string stmt = "SELECT COUNT(*) FROM dbo.CUSTOMERS"; int count = 0; using (SqlCommand cmdCount = new SqlCommand(stmt, con)) { con.Open(); count = (int)cmdCount.ExecuteScalar(); con.Close(); } EnterToGrid(count); } else if (e.CommandName == "CancelRow") { GridView1.EditIndex = -1; string stmt = "SELECT COUNT(*) FROM dbo.CUSTOMERS"; int count = 0; using (SqlCommand cmdCount = new SqlCommand(stmt, con)) { con.Open(); count = (int)cmdCount.ExecuteScalar(); con.Close(); } EnterToGrid(count); } else if (e.CommandName == "UpdateRow") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; int rollno = Convert.ToInt32(e.CommandArgument); string Full_Name = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox5")).Text; string Country = ((DropDownList)GridView1.Rows[rowIndex].FindControl("DropDownList1")).SelectedValue; string Company = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox2")).Text; string Email = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox4")).Text; CustomerDataAcessLayer.UpdateCustomer(rollno, Full_Name, Company, Country, Email); GridView1.EditIndex = -1; string stmt = "SELECT COUNT(*) FROM dbo.CUSTOMERS"; int count = 0; using (SqlCommand cmdCount = new SqlCommand(stmt, con)) { con.Open(); count = (int)cmdCount.ExecuteScalar(); con.Close(); } EnterToGrid(count); } }
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e) { { if (e.CommandName == "EditSearch") { // Response.Write(SearchText); int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; GridView2.EditIndex = rowIndex; string stmt = "SELECT COUNT(*) FROM dbo.CUSTOMERS where Full_Name like '%'+@Full_Name+'%' OR Company like '%'+@Full_Name+'%'"; int count = 0; SqlCommand cmdCount = new SqlCommand(stmt, con); con.Open(); cmdCount.Parameters.AddWithValue("Full_Name", ViewState["SearchTB"]); count = (int)cmdCount.ExecuteScalar(); con.Close(); EnterAfterSearch(count); ViewState["editbtn"] = true; } else if (e.CommandName == "DeleteRow") { CustomerDataAcessLayer.DeleteCustomer(Convert.ToInt32(e.CommandArgument)); string stmt = "SELECT COUNT(*) FROM dbo.CUSTOMERS"; int count = 0; using (SqlCommand cmdCount = new SqlCommand(stmt, con)) { con.Open(); count = (int)cmdCount.ExecuteScalar(); con.Close(); } EnterToGrid(count); } else if (e.CommandName == "CancelSearch") { GridView2.EditIndex = -1; string stmt = "SELECT COUNT(*) FROM dbo.CUSTOMERS where Full_Name like '%'+@Full_Name+'%' OR Company like '%'+@Full_Name+'%'"; int count = 0; SqlCommand cmdCount = new SqlCommand(stmt, con); con.Open(); cmdCount.Parameters.AddWithValue("Full_Name", ViewState["SearchTB"]); count = (int)cmdCount.ExecuteScalar(); con.Close(); EnterAfterSearch(count); } else if (e.CommandName == "UpdateRow") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; int rollno = Convert.ToInt32(e.CommandArgument); string Full_Name = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox5")).Text; string Country = ((DropDownList)GridView1.Rows[rowIndex].FindControl("DropDownList1")).SelectedValue; string Company = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox2")).Text; string Email = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox4")).Text; CustomerDataAcessLayer.UpdateCustomer(rollno, Full_Name, Company, Country, Email); GridView1.EditIndex = -1; string stmt = "SELECT COUNT(*) FROM dbo.CUSTOMERS"; int count = 0; using (SqlCommand cmdCount = new SqlCommand(stmt, con)) { con.Open(); count = (int)cmdCount.ExecuteScalar(); con.Close(); } EnterToGrid(count); } } }