Home > Net >  The.net inside the gridview edit button Row_editing Row_updating Row_CancelingEdit a series of metho
The.net inside the gridview edit button Row_editing Row_updating Row_CancelingEdit a series of metho

Time:09-15

I use the dataset of SQL server binding table, want to add to edit, delete button, found all the way to write their own, that these functions how to implement?
This is the front desk



This is the background has been completed
Protected void Page_Load (object sender, EventArgs e)
{
if(! Page. IsPostBack)
{

SqlConnection myconn=new SqlConnection (" Data Source=LAPTOP - I5R4GJL7; Integrated Security=true; Initial Catalog=test ");
Myconn. The Open ();
SqlCommand CMD=new SqlCommand ();
CMD. Connection=myconn;
The DataSet myds=new DataSet ();
SqlDataAdapter myda=new SqlDataAdapter (" select * from student ", myconn);
Myda. The Fill (myds, "student");
GridView1. The DataSource=myds. Tables (" student ");
GridView1. DataKeyNames=new string [] {} "sid";
GridView1. DataBind ();
Myconn. Close ();

}
}



Protected void GridView1_RowDeleting (object sender, GridViewDeleteEventArgs e)
{
String mno=GridView1. DataKeys [" e.R owIndex]. Value. The ToString ();
SqlConnection myconn=new SqlConnection (" Data Source=LAPTOP - I5R4GJL7; Integrated Security=true; Initial Catalog=test ");
Myconn. The Open ();
SqlCommand comm=new SqlCommand (" delete from student where sid='" + mno + "' ", myconn);
Comm. ExecuteNonQuery ();
Myconn. Close ();
Response. Redirect (" stuManagement. Aspx ");
}

Protected void Button1_Click (object sender, EventArgs e)
{
SqlConnection myconn=new SqlConnection (" Data Source=LAPTOP - I5R4GJL7; Integrated Security=true; Initial Catalog=test ");
Myconn. The Open ();
SqlCommand CMD=new SqlCommand ();
CMD. Connection=myconn;
The DataSet myds=new DataSet ();
SqlDataAdapter myda=new SqlDataAdapter (" select * from student where sid='" + TextBox1. Text + "' or name='" + TextBox1. Text + "' ", myconn);
Myda. The Fill (myds, "student");
GridView1. The DataSource=myds. Tables (" student ");
GridView1. DataKeyNames=new string [] {} "sid";
GridView1. DataBind ();
Myconn. Close ();
}

Protected void GridView1_RowCancelingEdit (object sender, GridViewCancelEditEventArgs e)
{
Response. Redirect (" stuManagement. Aspx ");
}

Protected void GridView1_RowUpdating (object sender, GridViewUpdateEventArgs e)
{

}

Protected void GridView1_RowEditing (object sender, GridViewEditEventArgs e)
{

}

CodePudding user response:

https://www.cnblogs.com/a121984376/archive/2008/07/18/1245906.html

CodePudding user response:

Can be set using the sqldatasource binding, increase, delete, modify the statements and parameters can be

  • Related