Sie sind auf Seite 1von 3

using using using using using using using using using

System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls; System.Data.SqlClient; System.Configuration; System.Data;

public partial class Default2 : System.Web.UI.Page { string connection = ConfigurationManager.ConnectionStrings["constr"].Connect ionString; SqlDataAdapter DA; DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bindgrid(); } } protected void BtnSave(object sender, EventArgs e) { SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("insert into Category values('" + TextBo x1.Text + "','" + TextBox2.Text + "')", con); //Bindgrid(); cmd.ExecuteNonQuery(); con.Close(); Bindgrid(); } public void Bindgrid() { SqlConnection con = new SqlConnection(connection); con.Open(); DA = new SqlDataAdapter("Select * from Category", con); DA.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e ) { } //protected void Button1_Click(object sender, EventArgs e) //{ // SqlConnection con = new SqlConnection(); // con.Open(); // SqlCommand cmd = new SqlCommand("delete * from Category where Category ='"+TextBox1.Text+"',Description='"+TextBox2.Text+"')",con); // cmd.ExecuteNonQuery();

//

con.Close();

//} //protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e ) //{ // GridView1.EditIndex = e.NewEditIndex; // Bindgrid(); //} protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; TextBox textcategory = (TextBox)row.Cells[2].FindControl("TextBox4"); TextBox textDescription = (TextBox)row.Cells[3].FindControl("TextBox6") ; SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("update Category set Description='" + textDescription.Text + "' where categoryName='" + textcategory.Text + "'", con) ; cmd.ExecuteNonQuery(); con.Close(); GridView1.EditIndex = -1; Bindgrid(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditE ventArgs e) { GridView1.EditIndex = -1; Bindgrid(); } protected void TextBox6_TextChanged(object sender, EventArgs e) { } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; Bindgrid(); } protected void Button7_Click(object sender, EventArgs e) { } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; //TextBox textcategory = (TextBox)row.FindControl("TextBox4"); Label lbldeleteID = (Label)row.FindControl("Label1"); SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("delete from Category where categoryName ='" + lbldeleteID.Text + "'", con);

cmd.ExecuteNonQuery(); Bindgrid(); con.Close(); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { TextBox txtcategoryName = (TextBox)GridView1.FooterRow.FindControl("Text Box8"); TextBox txtDescription = (TextBox)GridView1.FooterRow.FindControl("TextB ox7"); //Label lblDescription = (Label)GridView1.FooterRow.FindControl("Label2" ); SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("insert into Category values ('"+txtcate goryName.Text+"','"+txtDescription.Text+"')",con ); cmd.ExecuteNonQuery(); con.Close(); Bindgrid(); } }

Das könnte Ihnen auch gefallen