需要将动态值从ASP.NET文本框传递到报表查看器

时间:2016-11-02 04:12:40

标签: c# asp.net reportviewer

我认为这是基本的,但我是报道工具的新手。

我有一个Web表单,我有一些输入控件,我需要从DB中获取值以将它们填充到报表中。我必须能够以Excel或PDF格式获取报告,因此,我选择了提供这些功能的报告查看器。请检查下面的代码,并通过传递输入参数并获取生成的报告,为我提供有关如何开发报告的代码或想法。我的ASPX代码是:

<section id="content" class="has-btn-bar-btm-fixed"><!-- content -->
        <form runat="server" class="form-horizontal custom-form row">
          <div class="cost-transfer-block"><!-- cost-transfer-block -->
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-8 col-lg-10">
                            <h2>Dump by item</h2>


                                <div class="col-md-6">
                                    <div class="form-group">
                                        <asp:label runat="server" Text="From Site" ID="lblFromSite" class="control-label col-sm-3 col-md-3 col-lg-3" ></asp:label>
                                        <div class="col-sm-9">
                                            <div class="input-group">
                                                <select class="form-control">
                                                   <asp:DropDownList ID="DdlFromsite" runat="server" ></asp:DropDownList>
                                                </select>
                                                <span class="input-group-addon"><a href="javascript:;">&nbsp;</a></span>
                                            </div>
                                        </div>
                                    </div>



                                </div>
                                <div class="col-md-6 cst-brd-left">

                                    <div class="form-group">
                                        <asp:label runat="server" Text="From Date" ID="lblFromDate" class="control-label col-sm-3 col-md-3 col-lg-3" ></asp:label>
                                        <div class="col-sm-9  transferdate">
                                            <div class="input-group  date">
                                                <input type="date" class="form-control" id="" placeholder="Select Date" >
                                                <span class="input-group-addon"><a href="javascript:;"><img src="images/icon-add-on-2-date.png" alt="" /></a></span>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <asp:label runat="server" Text="To Date" ID="lblToDate" class="control-label col-sm-3 col-md-3 col-lg-3" >To Date</asp:label>
                                        <div class="col-sm-9  transferdate">
                                            <div class="input-group  date">
                                                <input type="date" class="form-control" id="" placeholder="Select Date" >
                                                <span class="input-group-addon"><a href="javascript:;"><img src="images/icon-add-on-2-date.png" alt="" /></a></span>
                                            </div>
                                        </div>
                                    </div>

                                </div>


                        </div>
                        <div class="col-md-4 col-lg-2">
                           &nbsp;
                        </div>
                    </div>
                </div>
          </div>
          <!-- /cost-transfer-block -->

          <div class="gray-btn-row clearfix">
                <div class="btns-group">
                    <asp:button runat="server" Text="Enter" ID="btnEnter" class="btn btn-dark-blue"></asp:button>
                </div>
          </div>

        </form>          
    </section>

请给我一个代码或想法,我可以通过点击Enter按钮生成报告。

先谢谢,

迪帕克

1 个答案:

答案 0 :(得分:0)

在按钮上调用Ajax ExportFile方法。

   public void ExportFile(Parameter1,parameter2)
     {
    var data ="Fire Query in database using Parameter and Get Data";
    Response.ClearContent();
    Response.AddHeader("content-disposition", "attachment;filename=Report.xlsx");
    Response.AddHeader("Content-Type", "application/vnd.ms-excel");  
    ExcelPackage objExcel = new ExcelPackage();
     ExcelWorksheet reportsheet = objExcel.Workbook.Worksheets.Add("Report");
                    reportsheet.Cells["A1"].LoadFromDataTable(AccessHelper.ToLocationDataTable(data), true);
     objExcel.Save();
     using (MemoryStream MyMemoryStream = new MemoryStream())
      {
     objExcel.SaveAs(MyMemoryStream);
    MyMemoryStream.WriteTo(Response.OutputStream);
     Response.Flush();
     Response.End();
     }
    }