After update the record refresh the page using the following code in DropDownList change event.
Response.Redirect(Request.Url.AbsoluteUri);
Code
protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DropDownList ddlStatus = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddlStatus.NamingContainer;
if (row.RowIndex >= 0 && row.RowIndex < gvReports.Rows.Count)
{
string id;
if (gvReports.DataKeys != null && gvReports.DataKeys.Count > row.RowIndex)
{
id = Convert.ToString(gvReports.DataKeys[row.RowIndex].Value);
string status = ddlStatus.SelectedValue;
string username = Session["Username"].ToString(); // Get the username from the session
// Log status change attempt
//System.Diagnostics.Debug.WriteLine($"Attempting to update ID: {id} to Status: {status} by User: {username}");
// Update status and rebind GridView
UpdateStatus(id, status, username);
}
}
}
catch (Exception ex)
{
// Log any errors
System.Diagnostics.Debug.WriteLine("Error in ddlStatus_SelectedIndexChanged: " + ex.Message);
}
finally
{
Response.Redirect(Request.Url.AbsoluteUri);
}
}