protected void muestra_seleccion(int v_tipo) { string queryString = ""; lbl_mensaje.Text = ""; queryString = "informe_clientes"; using (MySqlConnection conn = new MySqlConnection(SMysql)) { try { conn.Open(); MySqlCommand command = new MySqlCommand(queryString, conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@v_tipo", v_tipo); command.Parameters["@v_tipo"].Direction = ParameterDirection.Input; DataSet ds = new DataSet(); MySqlDataAdapter mysqlDAdp = new MySqlDataAdapter(command); MySqlDataReader dr = command.ExecuteReader(); if (!dr.HasRows) { lbl_mensaje.Text = "Informe no entregó resultados"; Lista_clientes.DataSource = null; Lista_clientes.DataBind(); } else { Lista_clientes.DataSource = dr; Lista_clientes.DataBind(); lbl_cantidad.Text = "Cantidad de Registros: " + Convert.ToString(Lista_clientes.Rows.Count); } //Productos.DataMember = "tbl_items"; conn.Close(); conn.Dispose(); } catch (Exception ex) { lbl_error.Text = ex.Message; conn.Close(); conn.Dispose(); } } }
protected void LnkBtn_Descargar_Click(object sender, EventArgs e) { if (Lista_clientes.Rows.Count > 0) { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=InformeClientes.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); //To Export all pages Lista_clientes.AllowPaging = false; // this.BindGrid(); Lista_clientes.HeaderRow.BackColor = Color.White; foreach (TableCell cell in Lista_clientes.HeaderRow.Cells) { cell.BackColor = Lista_clientes.HeaderStyle.BackColor; } foreach (GridViewRow row in Lista_clientes.Rows) { row.BackColor = Color.White; foreach (TableCell cell in row.Cells) { if (row.RowIndex % 2 == 0) { cell.BackColor = Lista_clientes.AlternatingRowStyle.BackColor; } else { cell.BackColor = Lista_clientes.RowStyle.BackColor; } cell.CssClass = "textmode"; } } Lista_clientes.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(); } } }