protected void grdMain_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "GetExcel") { DataTable DtCsv = CreateDt(); Int32 RowId = Convert.ToInt32(e.CommandArgument); GridViewRow CurRow = (GridViewRow)grdMain.Rows[RowId]; HiddenField hidLocId = (HiddenField)CurRow.FindControl("hidLocId"); HiddenField hidYearId = (HiddenField)CurRow.FindControl("hidYearId"); OpenTyreDAL objItemMastDAL = new OpenTyreDAL(); var lst = objItemMastDAL.GetExcel(Convert.ToInt64(hidLocId.Value), Convert.ToInt64(hidYearId.Value)); if (lst != null && lst.Count > 0) { for (int i = 0; i < lst.Count; i++) { ApplicationFunction.DatatableAddRow(DtCsv, Convert.ToString(DataBinder.Eval(lst[i], "SerialNo")), Convert.ToString(DataBinder.Eval(lst[i], "CompanyName")), Convert.ToString(DataBinder.Eval(lst[i], "LoctionName")), Convert.ToString(DataBinder.Eval(lst[i], "ItemName")), "", Convert.ToString(DataBinder.Eval(lst[i], "Rate")), ""); } if ((DtCsv != null) && (DtCsv.Rows.Count != 0)) { DtCsv.Columns["LoctionName"].Caption = "Location"; DtCsv.Columns["ItemName"].ColumnName = "TyreName"; DtCsv.Columns["Rate"].Caption = "Rate"; DtCsv.Columns["SerialNo"].SetOrdinal(0); DtCsv.Columns["CompanyName"].SetOrdinal(1); DtCsv.Columns["LoctionName"].SetOrdinal(2); DtCsv.Columns["TyreName"].SetOrdinal(3); DtCsv.Columns["Rate"].SetOrdinal(4); DtCsv.Columns.Remove("Qty"); DtCsv.Columns.Remove("Amount"); DtCsv.AcceptChanges(); ExportDataTableToCSV(DtCsv, Convert.ToString("OpeningItemDetails")); Response.Redirect("ManageOpenStock.aspx"); } } } }