1voto

exportar dos archivos desde dos gridview diferentes

hola buen día, tengo un problema al exportar dos archivos desde dos gridview diferentes.

lo que trataba de hacer era mandar a llamar el metodo que exporta mi csv dos veces , el primero con el primer gridview(funciona)

pero al finalizar el metodo se ejecuta la linea

response.end();

y no vuelve a llamar el metodo de exportar

este es mi código

protected void ExportarArchivos(GridView grid, int reporte)
        {

            String nombreArchivo = null, nombreArchivo2 = null;

            //Get the Reponse Ready for Exporting
            Response.Clear();
            Response.Buffer = true;
            Response.ContentEncoding = Encoding.GetEncoding("Windows-1252");

            if (reporte == 1) // Gasolina Informes mensuales
            {
                nombreArchivo = "30" + "RFCCUALLIX" + txtFechaInicio.Text.Substring(6, 4) + txtFechaInicio.Text.Substring(3, 2) + "001.csv";

            }
            else if (reporte == 2) // Gasolina
            {
                nombreArchivo2 = "30" + "RFCCUALLIX" + txtFechaInicio.Text.Substring(6, 4) + txtFechaInicio.Text.Substring(3, 2) + "201.csv";
            }
            else if (reporte == 3)
            {
                nombreArchivo = "31" + "RFCCUALLIX" + txtFechaInicio.Text.Substring(6, 4) + txtFechaInicio.Text.Substring(3, 2) + "001.csv";
            }
            //Set the name of your CSV file here

            if(reporte == 2)
            {
                Response.AddHeader("content-disposition", "attachment;filename=" + nombreArchivo2);
            }
            else
            Response.AddHeader("content-disposition", "attachment;filename=" + nombreArchivo);
            Response.Charset = "UTF-8";
            Response.ContentType = "application/text";

            //Creates a Stringbuilder to grab all of your columns
            StringBuilder sb = new StringBuilder();

            //Iterates through each of your rows
            for (int i = 0; i < grid.Rows.Count; i++)
            {
                for (int k = 0; k < grid.HeaderRow.Cells.Count; k++)
                {
                    String cadena = Server.HtmlDecode(grid.Rows[i].Cells[k].Text.ToUpper());
                    if(cadena == "&NBSP;")
                        cadena = "";

                    //Adds your Comma
                    if (k + 1 == grid.HeaderRow.Cells.Count)
                    {

                        sb.Append(cadena);

                    }
                    else
                        sb.Append(cadena + '|');
                }
                //Appends your New Line
                sb.Append("\r\n");
            }

            //Writes out your CSV File
            Response.Output.Write(sb.ToString());
            Response.Flush();

            Response.End();

        }

 protected void btnExportar_Click(object sender, EventArgs e)
        {

            if (ddlIdMonedero.SelectedValue == "55")
            {
                ExportarArchivos(grdDatos,1); // Informe Mensual
                ExportarArchivos(grdDatos2,2); // Estado de cuenta

            }
            else if (ddlIdMonedero.SelectedValue == "56")
            {
                ExportarArchivos(grdDatos,3); // Estado de cuenta

            }

        }

Por favor, accede o regístrate para responder a esta pregunta.

Otras Preguntas y Respuestas


...

Bienvenido a entre Desarrolladores, donde puedes realizar preguntas y recibir respuestas de otros miembros de la comunidad.

Conecta