using System.Web.UI.WebControls.WebParts; using System.IO; using System.Data.SqlClient; using System; using System.Web; using System.Web.UI; using System.Collections.Generic; using System.Data; using System.Reflection; using System.Web.UI.WebControls; using System.Configuration; public partial class admin_LeadPanel : System.Web.UI.Page { string strFrom, strFromR, strTo, strToR, dtyyyy, dtmm, dtdd, thh, tmm, tss; string[] strdate, strdate2; int index; public static DataSet GetDataByStoredProcedure(string procedureName, IEnumerable> parametersList = null) { DataSet result = new DataSet(); SqlConnection sqlConnection = new SqlConnection("Initial Catalog=Hiranandani_new;Data Source=52.172.39.101; User ID=sa; Password=!de@te$ec007;"); sqlConnection.Open(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(procedureName, sqlConnection); sqlDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure; if (parametersList != null) foreach (var item in parametersList) sqlDataAdapter.SelectCommand.Parameters.AddWithValue(item.Item1, item.Item2); sqlDataAdapter.Fill(result); sqlConnection.Close(); return result; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Convert.ToString(Session["Name"]) == "" || Session["Name"] == null) { Response.Redirect("login.aspx"); } var data = GetDataByStoredProcedure("usp_GetLeadDetailsForPlomotion"); GridViewLeads.DataSource = data.Tables[0]; GridViewLeads.DataBind(); } } private void ExportToExcel(Control webControl, string filename) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".xls"); HttpContext.Current.Response.Charset = ""; HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; StringWriter sWriter = new StringWriter(); HtmlTextWriter hWriter = new HtmlTextWriter(sWriter); GridViewLeads.RenderControl(hWriter); HttpContext.Current.Response.Output.Write(sWriter.ToString()); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } protected void btnsubmit_Click(object sender, EventArgs e) { try { //a(); ExportToExcel(GridViewLeads, "Hirco_" + DateTime.Now.Date); } catch (Exception ex) { //lblError.Text = ex.ToString(); } } public override void VerifyRenderingInServerForm(Control control) { } protected void btnSubmit1_Click(object sender, EventArgs e) { bindGrid(); } public void bindGrid() { List> parametersList = new List>(); parametersList.Add(new Tuple("@FromDate", txtFrom.Text)); parametersList.Add(new Tuple("@ToDate", txtTo.Text)); //parametersList.Add(new Tuple("@FormType", ddlFormType.SelectedValue)); var data = GetDataByStoredProcedure("usp_GetLeadDetailsForPlomotion", parametersList); GridViewLeads.DataSource = data.Tables[0]; GridViewLeads.DataBind(); } protected void BtnLogout_Click(object sender, EventArgs e) { Session.Clear(); Response.Redirect("Login.aspx"); } }