using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; using System.Configuration; using System.Data.SqlClient; public partial class Admin_Default2 : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString); protected void Page_Load(object sender, EventArgs e) { } public void viewStudentDetailNew() { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "viewStudentDetailNew"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@branchid", HiddenBranch.Value); cmd.Parameters.AddWithValue("@status", 3); cmd.Parameters.AddWithValue("@PageNumber", 1); cmd.Parameters.AddWithValue("@PageSize", 500); DataTable dt = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(); adp.Fill(dt); if(dt.Rows.Count>0) { } } public void ExportToExcel(DataTable dt) { if (dt.Rows.Count > 0) { string filename = "DownloadMobileNoExcel.xls"; System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw); DataGrid dgGrid = new DataGrid(); dgGrid.DataSource = dt; dgGrid.DataBind(); //Get the HTML for the control. dgGrid.RenderControl(hw); //Write the HTML back to the browser. //Response.ContentType = application/vnd.ms-excel; Response.ContentType = "application/vnd.ms-excel"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + ""); this.EnableViewState = false; Response.Write(tw.ToString()); Response.End(); } } }