我使用datagridview创建了一个订单webform,我使用crystal report创建了一个报表。我还将crystalreportviewer放到datagridview同一页面。
这是webform和datagridview的gridview列的列表:
<asp:GridView ID="GridViewHome" runat="server" AllowPaging="True" AutoGenerateColumns="false" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnPageIndexChanging="GridViewHome_PageIndexChanging">
<Columns>
<asp:TemplateField>
<HeaderTemplate>Patient MRN#</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblpatient" runat="server" Text='<%# Eval("Patient No") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Order Number</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblorder" runat="server" Text='<%# Eval("Request number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Patient Name</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%# Eval("Patient Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Req. Date</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblreqd" runat="server" Text='<%# Eval("Request Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Report Date</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblrepd" runat="server" Text='<%# Eval("Report Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Test Name</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" runat="server" Text='<%# Eval("Test_Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Result</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="result" runat="server" Text='<%# Eval("Result") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Ref.Range From</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Reflow" runat="server" Text='<%# Eval("Low Range") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>To</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="refhigh" runat="server" Text='<%# Eval("High Range") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Text Range</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="textrange" runat="server" Text='<%# Eval("Text Range") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>REQ. FORM NO.</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="req" runat="server" Text='<%# Eval("REQ FORM NUMBER") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Dept.Id</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="deptid" runat="server" Text='<%# Eval("DEPT ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Department</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="deptname" runat="server" Text='<%# Eval("Department") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Options</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="Lnkresult" runat="server" OnClick="Lnkresult_Click">Print Result</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
我希望按下链接按钮(打印结果)根据OrderNum和deptid参数显示报告down datagridview。
我创建了linkbutton,我使用了以下代码:
protected void Lnkresult_Click(object sender, EventArgs e)
{
GridViewRow iRow = ((GridViewRow)((LinkButton)sender).NamingContainer);
//Assuming you first column is where your "lblOrder" is.
int OrderNum = Convert.ToInt32(((Label)iRow.Cells[1].Controls[1]).Text);
int Deptid = Convert.ToInt32(((Label)iRow.Cells[11].Controls[1]).Text);
ReportDocument myReportDocument;
myReportDocument = new ReportDocument();
myReportDocument.Load(Server.MapPath("~/RPT/RPT_RESULTS.rpt"));
myReportDocument.SetParameterValue("@ORDER_ID", OrderNum);
myReportDocument.SetParameterValue("@deptid", Deptid);
myReportDocument.SetDatabaseLogon("username", "password");
CrystalReportViewer1.ReportSource = myReportDocument;
CrystalReportViewer1.DisplayToolbar = true;
}
但当我点击链接按钮时,它不会显示报告我的代码有什么错误?
您可以在datagridview中添加超链接并调用webform并使用以下代码将参数发送到crystal report查看器:
<asp:TemplateField>
<HeaderTemplate>Options</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" NavigateUrl='<%#"/RPT/WebForm1.aspx?order_id=" +Eval("Request number")+"&DEPT ID=" +Eval("DEPT ID")+"&Test Id=" +Eval("Test Id")%>' runat="server">Print Result</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
并在webform的页面加载中创建文本框2或3或4文本框的数量取决于您的参数然后在页面加载中使用此代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TXTORDERID.Text = Request.QueryString["order_id"].ToString();
TXTDEPTID.Text = Request.QueryString["DEPT ID"].ToString();
TXTTESTID.Text = Request.QueryString["Test Id"].ToString();
ReportDocument reportDocument = new ReportDocument();
ParameterFields paramFields = new ParameterFields();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "@ORDER_ID";
paramDiscreteValue.Value = TXTORDERID.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField();
paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "@deptid";
paramDiscreteValue.Value = TXTDEPTID.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
reportDocument.Load(Server.MapPath("~/RPT/RPT_RESULT.rpt"));
CrystalReportViewer1.ReportSource = reportDocument;
reportDocument.SetDatabaseLogon("DBA", "2006");
}
}