如何在asp.net

时间:2018-04-16 18:29:16

标签: c# asp.net gridview crystal-reports

在我的asp.net C#程序中包含Crystal报表代码后,我在代码中遇到问题。

我在VS2010中设置的Web应用程序中有一个Cheque.aspx文件,其中包含所有" Payees"正在加载Page_Load。在动态生成的GridView中单击收款人(OnSelectedIndexChanged())结果,并在单独的单独行中对该收款人进行所有检查。 Gidview最后一栏包括各种命令按钮(编辑,删除,提交,打印)。使用"打印" onclick事件我想打开一个水晶视图报告,检查前进的打印活动。 (已安装Crystal Reports for .NET Framework 4.0)。 在aspx文件中,我添加了Register Assembly命令,如下所示:

 `<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>`  

GridView和CR标签包含如下:

 <div class="scroll">
 <asp:GridView ID="ChqOuterGridView" runat="server" AutoGenerateColumns="false" 
                             OnDataBound="ChqOuterGridView_DataBound" OnRowDataBound="GridViewRowDataBound"
                            DataKeyNames="Id,ChqNo,Action,TotChqAmt,PayeeName" Caption="" 
                             BorderStyle="Solid" OnRowEditing="ChqOuterGridView_RowEditing" 
                            OnRowDeleting="ChqOuterGridView_RowDeleting" OnRowUpdating="ChqOuterGridView_RowUpdating"
                             OnRowCommand="ChqOuterGridView_RowCommand">
 <columns>
 <asp:TemplateField HeaderText="Cheque No" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
    <ItemTemplate>
       <asp:Label ID="lblCHqNo" runat="server" Text='<%# Eval("ChqNo")%>'></asp:Label>
      </ItemTemplate>
   </asp:TemplateField>
 <asp:TemplateField ItemStyle-Width="90px" HeaderText="Total Cheque Amount" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
     <ItemTemplate>
       <asp:Label ID="lblTotAmt" runat="server" Text='<%# ((Convert.ToDecimal(Eval("TotChqAmt")))*1000000).ToString("##,##0.######") %>'>
         </asp:Label>
    </ItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField ItemStyle-Width="150px" HeaderText="Action" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
   <ItemTemplate>
     <asp:Button ID="BtnEdit" runat="server" CommandName="Edit" SkinID="1" Text="" />
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <asp:Button ID="BtnDelete" runat="server" CommandName="Delete" SkinID="2" Text="" />
   <br />
       <asp:Button ID="BtnPrintCheque" runat="server" CommandName="Update" Text="Print Cheque" CommandArgument="Print"/>
   <br />
      <asp:Button ID="BtnSend" runat="server" CommandName="Update" Text="Send  to Accountant" CommandArgument="Send"/>
</ItemTemplate>
</asp:TemplateField>
 </Columns>
</asp:GridView>
 </div>
 <div>
    <CR:CrystalReportViewer ID="crptViewer" runat="server" AutoDataBind="true"/>
 </div> 

gridview_RowUpdating按钮点击事件后面的代码(cheque.aspx.cs)中的Crystal Report代码如下:

public void ChqOuterGridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)
{
  string ChqNo = (string)ChqOuterGridView.DataKeys[e.RowIndex]["ChqNo"];
  if (CommandArgument == "Print")
  {
      ReportDocument rptDoc = new ReportDocument();
      rptDoc.Load(Server.MapPath("~/Reports/CR/PrintCheque.rpt"));

  DataTable dataTable1 = new DataTable();

  dataTable1.Columns.Add("PayeeName", typeof(String));
  dataTable1.Columns.Add("AmountinFigures", typeof(Decimal));

  DataRow dtRow = dataTable1.NewRow();

  dtRow["PayeeName"] = ChqOuterGridView.DataKeys[e.RowIndex]["PayeeName"];
  dtRow["AmountinFigures"] = ChqOuterGridView.DataKeys[e.RowIndex]["TotChqAmt"];

  dataTable1.Rows.Add(dtRow);
  MyDataSet mds = new MyDataSet();
  mds.Tables.Add(dataTable1);

  rptDoc.SetDataSource(mds);
  crptViewer.ReportSource = rptDoc; 
//   CrystalReportViewer1.RefreshReport();
    }
}

数据集在〜/ App_Code / MyDataSet.xsd中创建,晶体报告相应地设置了两列。 web.config包含以下相关条目:

 <configSections>
        <sectionGroup name="businessObjects">
          <sectionGroup name="crystalReports">
            <section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null"/>
            <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler"/>
          </sectionGroup>
        </sectionGroup>
      </configSections>

<assemblies>  
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</assemblies>

如果我删除Crystal报表标签和相关代码,ListBox OnSelectedIndexChanged()工作正常并显示Gridview。但是在包含Crystal Report标签后,页面将被加载并显示Listbox元素但点击一个元素没有任何效果。

有人可以建议ListBox项目不能触发OnSelectedIndexChanged()的原因吗?

0 个答案:

没有答案