Quote:
delete those client which are stored in the table client but after updating it they should not be there.
You just need to re-bind your GridView to reflect the changes you've made. So when you Update or Delete data, do something like this:
private void BindGrid(){
using (SqlConnection sqlConn = new SqlConnection
(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString)){
string sql = "SELECT * FROM YourTableName";
using(SqlCommand sqlCmd = new SqlCommand(sql,sqlConn)){
sqlConn.Open();
using(SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCmd)){
sqlAdapter.Fill(dt);
}
}
}
if(dt.Rows.Count > 0){
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
then at RowUpdating and RowDeleting events, you simply call the method BindGrid() to refresh your Grid with the changes:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e){
BindGrid();
}
Please do take note of the following:
(1) Store your connection string in your web.config, rather than hard-coding it in your code behind.
(2) Always use Parameter Queries when passing parameters to your SQL query. Here's another reference that you may want to look at:
Protect Your Data: Prevent SQL Injection[
^]
(3) Remember to use the "Using Block" when dealing with objects that eat resources, such as: SqlConnection and SqlCommand