I have a gridview. When I edit records, records only update in the database, not in client side. In client side, old records are displayed.
I want to refresh gridview when I click update button so that records in database will be displayed in client side.
This is the code:
protected void Update(object sender, EventArgs e)
{
DataTable dt = new DataTable();
foreach (GridViewRow row in grid1.Rows)
{
int id = int.Parse((row.FindControl("LblOrderId") as Label).Text);
int orderAmount = int.Parse((row.FindControl("txtOrderAmount") as TextBox).Text);
int affec = UpdateAmount(orderAmount, id);
}
}
public int UpdateAmount(int amount, int id)
{
using (SqlConnection con = Connection_Manager.connection_String())
{
con.Open();
string sql = "update order_test set amount = @amount where id=@id";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@amount", amount);
cmd.Parameters.AddWithValue("@id", id);
int affected = cmd.ExecuteNonQuery();
return affected;
}
}