private void BindGridView() { SqlConnection con = new SqlConnection(_ConnStr); con.Open(); SqlCommand cmd = new SqlCommand("select SQ_Slno,SQ_RFQ_Number,M_Company.M_Company_Name,SQ_OfferPrice,SQ_RFQ_ExpectedPrice,SQ_RFQ_OriginCountry,SQ_RFQ_DestinationCountry,SQ_RFQ_OriginAirport,SQ_RFQ_DestinationAirport from SQ inner join M_Company on SQ.SQ_Company = M_Company.M_Company_Slno where SQ_RFQ_Number = @rfqnumber order by SQ_OfferPrice", con); cmd.Parameters.AddWithValue("@rfqnumber", dropdownseller.SelectedItem.Value); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); RateComparisonGridView.DataSource = ds; RateComparisonGridView.DataBind(); con.Close(); }
protected void ExportToExcel(object sender, EventArgs e) { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=ratecomparisonreports.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); //To Export all pages RateComparisonGridView.AllowPaging = false; this.BindGridView(); RateComparisonGridView.HeaderRow.BackColor = Color.White; foreach (TableCell cell in RateComparisonGridView.HeaderRow.Cells) { cell.BackColor = RateComparisonGridView.HeaderStyle.BackColor; } foreach (GridViewRow row in RateComparisonGridView.Rows) { row.BackColor = Color.White; foreach (TableCell cell in row.Cells) { if (row.RowIndex % 2 == 0) { cell.BackColor = RateComparisonGridView.AlternatingRowStyle.BackColor; } else { cell.BackColor = RateComparisonGridView.RowStyle.BackColor; } cell.CssClass = "textmode"; } } RateComparisonGridView.RenderControl(hw); //style to format numbers to string string style = @"<style> .textmode { } </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } }