1

PD: Falta de informacion: lo que quiero mostrar en el gridview son solo los datos que inserto a la BD desde el excel NO quiero mostrar TODOS los registros de esta. buenas tardes comunidad mi duda es la siguente resulta que hice un file upload en MVC 2 (aspx) que me lee un excel y lo exporta a una BBDD desde la vista ahora mi pregunta es la siguiente como puedo mostrar en una grilla ese dataset que tengo creado en el controller Extracto del Codigo C#

 private void InsertExceldata(string fileepath, string filename)
    {
        string fullpath = Server.MapPath("/excelFolder/") + filename;
        ExcelConn(fullpath);
        string query = string.Format("Select * from[FP diario$]");
        string fecha = string.Format("Select * from[TCO$C4:C5]");
        string nombre = string.Format("Select * from[FP diario$B2:B500]");
        OleDbCommand Ecom = new OleDbCommand(query, Econ);
        OleDbCommand Efech = new OleDbCommand(fecha, Econ);
        OleDbCommand Enombre = new OleDbCommand(nombre, Econ);
        Econ.Open();
        DataSet ds = new DataSet();
        DataSet fech = new DataSet();
        DataSet nombreds = new DataSet();
        OleDbDataAdapter oda = new OleDbDataAdapter(query, Econ);
        OleDbDataAdapter odafech = new OleDbDataAdapter(fecha, Econ);
        OleDbDataAdapter odanombre = new OleDbDataAdapter(nombre, Econ);
        Econ.Close();
        oda.Fill(ds);
        odafech.Fill(fech);
        odanombre.Fill(nombreds);
        ds.Tables[0].Rows.RemoveAt(0);
        ds.Tables[0].AcceptChanges();
        DataTable dt = ds.Tables[0];
        DataTable df = fech.Tables[0];
        DataTable dn = nombreds.Tables[0];}

Codigo aspx

     <div class="col-lg-6 col-sm-6 col-12">
    <%using (Html.BeginForm("Mantenedor", "Mantenedor", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {%>
    <h4>Factor de Penalización</h4>
    <div class="input-group">

        <input type="text" class="form-control" readonly>
        <label class="input-group-btn">
            <span class="btn btn-primary" style="right: 209px;">Seleccionar Archivo…
                <input type="file" name="file" id="file" style="display: none;" multiple="">
            </span>
        </label>


    </div>
    <div>
        <input type="submit" value="Subir PO.xls" class="btn btn-primary" style="margin-top: 1px;">
    </div>
    <% } %>
    <span class="help-block"></span>
</div>
<script>
    $(function () {

        // We can attach the `fileselect` event to all file inputs on the page
        $(document).on('change', ':file', function () {
            var input = $(this),
                numFiles = input.get(0).files ? input.get(0).files.length : 1,
                label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
            input.trigger('fileselect', [numFiles, label]);
        });

        // We can watch for our custom `fileselect` event like this
        $(document).ready(function () {
            $(':file').on('fileselect', function (event, numFiles, label) {

                var input = $(this).parents('.input-group').find(':text'),
                    log = numFiles > 1 ? numFiles + ' files selected' : label;

                if (input.length) {
                    input.val(log);
                } else {
                    if (log) alert(log);
                }

            });
        });

    });
</script>


<p>
    &nbsp;
</p>
1
  • No podes asignar la información del ds a un viewmodel para pasarlo a la vista? el 7 may. 2018 a las 18:37

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.