Sathya Narayan

Sathya Narayan

  • NA
  • 155
  • 63.7k

Unable to evaluate expression because the code is optimized

Nov 18 2016 5:07 AM
Hi,
I am getting the unable to evaluate expression because the code is optimized or a native frame is on top of the call error after the response.end().Whats my problem is when i click the button i can able to download the excel sheet but the gridview which has not getting refreshed when it gets updated.
 
 
public void BindGridExistingMapping(DataSet ds)
{
try
{
gvexistpincodemapping.DataSource = null;
if (ds.Tables[0].Rows.Count > 0)
{
gvexistpincodemapping.DataSource = ds.Tables[0];
}
gvexistpincodemapping.DataBind();
}
catch (Exception ex)
{
lblErrorMsg.Visible = true;
lblErrorMsg.ForeColor = System.Drawing.Color.Green;
lblErrorMsg.Text = "";
lblErrorMsg.Text = "Error ";
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
try
{
gvexistpincodemapping.DataSource = null;
gvexistpincodemapping.DataBind();
objCityBO._StateId = Convert.ToInt32(ddlState.SelectedItem.Value);
objCityBO._CityId = Convert.ToInt32(ddlCity.SelectedItem.Value);
objCityBO = objCityBLL.SelectCityByCityID(objCityBO);
objCityBO._ZoneID = objCityBLL.SelectCityByCityID(objCityBO)._ZoneID;
if (ddlState.SelectedItem.Value != "-1")
objBranchPinCodeBO._StateID = Convert.ToInt32(ddlState.SelectedItem.Value);
if (ddlCity.SelectedItem.Value != "-1")
objBranchPinCodeBO._City = Convert.ToInt32(ddlCity.SelectedItem.Value);
//objPinCodeMapBO._ZoneID = ZoneID;
objBranchPinCodeBO._ZoneID = objCityBO._ZoneID;
objBranchPinCodeBO._OldBranchID = Convert.ToInt32(ddlBranch.SelectedItem.Value);
objBranchPinCodeBO._OldBranchName = ddlBranch.SelectedItem.Text;
objBranchPinCodeBO._NewBranchID = Convert.ToInt32(ddlupdatebranch.SelectedItem.Value);
objBranchPinCodeBO._NewBranchName = ddlupdatebranch.SelectedItem.Text;
bool Update;
Update = objBranchPinCodeBLL.UpdatePinCodeCityMapping(objBranchPinCodeBO);
//FilterByNewBranch();///
lblErrorMsg.Visible = true;
lblErrorMsg.ForeColor = System.Drawing.Color.Green;
lblErrorMsg.Text = "Updated Successfully.";
//FliterByNewbranch();
DataSet dsSource = PinCodesByBranchId(int.Parse(ddlupdatebranch.SelectedItem.Value));
BindGridExistingMapping(dsSource);//Binding the New Data with gridview by branch id
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Reports.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
if (dsSource.Tables[0].Rows.Count > 0)
{
dsSource.Tables[0].Columns.Remove("MapCityId");
dsSource.Tables[0].Columns.Remove("StateId");
dsSource.Tables[0].Columns.Remove("State");
dsSource.Tables[0].Columns.Remove("CityId");
dsSource.Tables[0].Columns.Remove("BranchId");
dsSource.Tables[0].Columns.Remove("ZoneId");
dsSource.Tables[0].Columns.Remove("IsActive");
GridView1.DataSource = dsSource;
}
GridView1.DataBind();
//Change the Header Row back to white color
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < gvexistpincodemapping.HeaderRow.Cells.Count; i++)
{
GridView1.HeaderRow.Cells[i].Style.Add("background-color", "#78CFE3");
}
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
//Response.Flush();
Response.End();
//HttpContext.Current.ApplicationInstance.CompleteRequest();
}
//
catch (Exception ex)
{
//Response.Write(ex.Message);
//throw ex;
}
finally
{
//Response.End();
}
}

Answers (1)