Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I built an orders webform with datagridview , and built another webform with crystal report viewer control. I built also one report by using crystal report . I need from datagridview when i press linkbutton (print Result) send order number to that webform and crystal report and print out my order details in crystal report viewer. How can I program the link button in gridview to call the crystal report viewer and run the report depends on selected row and order number in datagridview :

This is the html code for webform and datagridview :

<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 MRN#</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPatient" runat="server" Text='<%# Eval("Patient No") %>'></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>Request Date</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblreqdate" runat="server" Text='<%# Eval("Request Date") %>'></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>Options</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton commandname="Select" ID="Lnkresult" runat="server">Print Result</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>


</Columns>

<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<SortedAscendingCellStyle BackColor="#FEFCEB" />
<SortedAscendingHeaderStyle BackColor="#AF0101" />
<SortedDescendingCellStyle BackColor="#F6F0C0" />
<SortedDescendingHeaderStyle BackColor="#7E0000" />

</asp:GridView>

What I have tried:

This is the code to run crystal report viewer from windows form application i think i need to update this code to use it in webform :

RPT.RPT_RESULTS report = new RPT.RPT_RESULTS();
report.SetParameterValue("@ORDER_ID", txtorder.Text);
report.SetParameterValue("@deptid", deptid);
RPT.RPT_TESTS form = new RPT.RPT_TESTS();
form.crystalReportViewer1.ReportSource = report;
form.ShowDialog();


I expect when press the link button (Print Result) to send order number to another webform with crystal report viewer and print out order details on that report , but i cannot program the link button.
Posted
Updated 29-Jan-19 6:48am

1 solution

Hi there,

Your linkbutton's click event needs to be wired:

<asp:LinkButton ID="lkBtnReport" runat="server" class="btn btn-xs" style="cursor:pointer" OnClick="lkBtnReport_Click">Show Report</asp:LinkButton>
Inside said event handler, use thew following line of code to identify the row that houses the linkbutton which triggered the event. This way, you'll be able to get your Order Number, etc. from it.
 protected void lnkBttnDescartar_Click(object sender, EventArgs e)
{
        GridViewRow iRow = ((GridViewRow)((LinkButton)sender).NamingContainer);

        //Assuming you first column is where your "lblOrder" is.
        string OrderNum = ((Label)iRow.Cells[0].Controls[1]).Text;
        ....
}
Once you have obtained the data you need to pass as parameters for your report, and redirect:
C#
Response.Redirect("http://YourDomain/YourReportPage.aspx?g=1&i=1", false);


I will leave setting the crystal report up to you.

Cheers!
 
Share this answer
 
Comments
Member 13505603 30-Jan-19 17:23pm    
thank you for your help i created the following code onclick for linkbutton
protected void Lnkresult_Click(object sender, EventArgs e)
{
GridViewRow iRow = ((GridViewRow)((LinkButton)sender).NamingContainer);

//Assuming you first column is where your "lblOrder" is.
string OrderNum = ((Label)iRow.Cells[0].Controls[1]).Text;
string Deptid = ((Label)iRow.Cells[1].Controls[1]).Text;

ReportDocument reportDocument = new ReportDocument();
reportDocument.Load("~/RPT/RPT_RESULTS.rpt");
reportDocument.SetParameterValue("@ORDER_ID", OrderNum);
reportDocument.SetParameterValue("@deptid", Deptid);
}
but when i click print result the following error show
Unsupported Operation. A document processed by the JRC engine cannot be opened in the C++ stack.
the error in this line :
reportDocument.Load("~/RPT/RPT_RESULTS.rpt");
Can I run the report direct from the path or i need to add it to another webform first with crystal report viewer and run that webform ?
alexvw 1-Feb-19 14:32pm    
Hi there,

I am afraid I can't give you a hand with Crystal Reports; I have not use them in more than 10 years.

Sorry.
Member 13505603 25-Feb-19 0:32am    
what if i have 3 parameters how to add it
string OrderNum = ((Label)iRow.Cells[0].Controls[1]).Text;
string OrderNum = ((Label)iRow.Cells[1].Controls[1]).Text;
string OrderNum = ((Label)iRow.Cells[2].Controls[1]).Text;
is this way correct ?
alexvw 25-Feb-19 9:22am    
Hi there,

Almost; in your code you are using the same variable over and over: OrderNum will have the last value assigned to it.

It should be something like this:

string OrderNum = ((Label)iRow.Cells[0].Controls[1]).Text;
string OrderDate = ((Label)iRow.Cells[1].Controls[1]).Text;
etc...

CAUTION! if you are reading data from a cell that does not have a label or any other control inside of it, just read its text property:
string anotherVar = iRow.Cells[3].Text;

Cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900