protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DB_Function.OpenConniction();
string ExpID = GridView2.DataKeys[e.RowIndex].Value.ToString();
string CompNm = ((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string JobTitel = ((TextBox)GridView2.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string WorkPlace = ((TextBox)GridView2.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
string StartDate = ((TextBox)GridView2.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
string EndDate = ((TextBox)GridView2.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
string ReasonLeave = ((TextBox)GridView2.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
string CompPhone = ((TextBox)GridView2.Rows[e.RowIndex].Cells[7].Controls[0]).Text;
if(DB_Function.UpdateExperiance(ExpID)>0)
{
GridView1.EditIndex = -1;
lblState.Text = " Row is Updated ";
lblState.ForeColor = System.Drawing.Color.Blue;
}
}
public static int UpdateExperiance(string ExpID , string CompNm , string JobTitel , string WorkPlace , string StartDate , string EndDate , string ReasonLeave , string CompPhone)
{
string Strcon = @"Data Source=MAHMOD-PC\SQLEXPRESS;Initial Catalog=Task;Integrated Security=True";
SqlConnection con = new SqlConnection(Strcon);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_U_Experiances";
cmd.Parameters.AddWithValue("@ExpID", ExpID);
cmd.Parameters.AddWithValue("@CompNm", CompNm);
cmd.Parameters.AddWithValue("@JobTitel", JobTitel);
cmd.Parameters.AddWithValue("@WorkPlace", WorkPlace);
cmd.Parameters.AddWithValue("@StartDate", StartDate);
cmd.Parameters.AddWithValue("@EndDate", EndDate);
cmd.Parameters.AddWithValue("@ReasonLeave", ReasonLeave);
cmd.Parameters.AddWithValue("@CompPhone", CompPhone);
con.Open();
return cmd.ExecuteNonQuery();
}
答案 0 :(得分:-1)
执行数据库更新后,您不会重新绑定数据。
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DB_Function.OpenConniction();
string ExpID = GridView2.DataKeys[e.RowIndex].Value.ToString();
string CompNm = ((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string JobTitel = ((TextBox)GridView2.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string WorkPlace = ((TextBox)GridView2.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
string StartDate = ((TextBox)GridView2.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
string EndDate = ((TextBox)GridView2.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
string ReasonLeave = ((TextBox)GridView2.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
string CompPhone = ((TextBox)GridView2.Rows[e.RowIndex].Cells[7].Controls[0]).Text;
if(DB_Function.UpdateExperiance(ExpID)>0)
{
GridView1.EditIndex = -1;
lblState.Text = " Row is Updated ";
lblState.ForeColor = System.Drawing.Color.Blue;
BindData();
}
}
BindData是您检索数据的地方:
private void BindData()
{
GridView2.DataSource = (your data source);
GridView2.DataBind();
}