| Author: Anu 06 Jul 2007 | Member Level: Gold Points : 0 |
As in code the data is exporting from DataGrid not directly from DataSet. The given title for the code is wrong. It title should be "Export Grid Data To Excel file" not "Create excel file from dataset "
|
| Author: Anil panwar 09 Dec 2009 | Member Level: Bronze Points : 2 |
protected void Button1_Click1(object sender, EventArgs e) { int min=0; String strsql1; DateTime Sdate; DateTime Edate; try { lobj = new UIRptServer.CommonFunctions(); String Strsql = "select datediff(day,'12/08/2009','12/08/2009')+1 as cnt"; idatatable = lobj.ReturnDataTable(Strsql); if (idatatable.Rows.Count > 0) { String _min = idatatable.Rows[0]["cnt"].ToString(); min = Int32.Parse(_min) * 24 * 60 - 1; } strsql1 = "select * from ViewMobileKeywordDetails where keywordmasterid=3702 and applydate between '12/08/2009' and dateadd(minute," + min + ",'12/08/2009') order by Applydate"; idatatable1 = lobj.ReturnDataTable(strsql1);
System.Web.UI.WebControls.DataGrid grid =new System.Web.UI.WebControls.DataGrid(); grid.HeaderStyle.Font.Bold = true; grid.DataSource = idatatable1; grid.DataBind(); // render the DataGrid control to a file _strpath = Server.MapPath(".") + "/Reports/" + "Anil" + "MSG" + "test.xls"; using (StreamWriter sw = new StreamWriter(_strpath)) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { grid.RenderControl(hw); } } } catch (Exception ex) { throw; } }
|