private void BindGridDB() { RateMastFTDAL objRateMstFT = new RateMastFTDAL(); DataTable dt1 = new DataTable(); DataRow Dr; DtTemp = CreateDt(); dt1 = objRateMstFT.SelectDBData(Convert.ToInt64(ddlLorryType.SelectedValue), Convert.ToInt32(drpBaseCity.SelectedValue), ApplicationFunction.ConnectionString()); if (dt1 != null && dt1.Rows.Count > 0) { for (int i = 0; i < dt1.Rows.Count; i++) { Dr = DtTemp.NewRow(); Dr.BeginEdit(); Dr[0] = DtTemp.Rows.Count == 0 ? 1 : DtTemp.Rows.Count + 1; Dr[1] = Convert.IsDBNull(dt1.Rows[i]["City_FIdno"]) ? "0" : Convert.ToString(dt1.Rows[i]["City_FIdno"]); Dr[2] = Convert.IsDBNull(dt1.Rows[i]["City_FName"]) ? "0" : Convert.ToString(dt1.Rows[i]["City_FName"]); Dr[3] = Convert.IsDBNull(dt1.Rows[i]["Lorry_Idno"]) ? "0" : Convert.ToString(dt1.Rows[i]["Lorry_Idno"]); Dr[4] = Convert.IsDBNull(dt1.Rows[i]["Lorry_Type"]) ? "0" : Convert.ToString(dt1.Rows[i]["Lorry_Type"]); Dr[5] = Convert.IsDBNull(dt1.Rows[i]["Rate_Date"]) ? "" : Convert.ToDateTime((dt1.Rows[i]["Rate_Date"])).ToString(); Dr[6] = Convert.IsDBNull(dt1.Rows[i]["ToCity_Idno"]) ? "0" : Convert.ToString(dt1.Rows[i]["ToCity_Idno"]); Dr[7] = Convert.IsDBNull(dt1.Rows[i]["City_Name"]) ? "0" : Convert.ToString(dt1.Rows[i]["City_Name"]); Dr[8] = Convert.IsDBNull(dt1.Rows[i]["Item_Rate"]) ? "0" : Convert.ToDouble(dt1.Rows[i]["Item_Rate"]).ToString("N2"); Dr.EndEdit(); DtTemp.Rows.Add(Dr); } ViewState["dt"] = DtTemp; ViewState["newNdt"] = DtTemp; BindGrid(); imgBtnExcel.Visible = true; } else { ViewState["dt"] = null; BindGrid(); imgBtnExcel.Visible = false; } }