Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
any one of you will help me to solve this problem..
I have a column in a gridview which will be also have Link Button Called “select” when it is clicked it will go to the crystal report page and show this row record in crystal report page.
I am using Crystal Report viewer.
Please guide me on this.
rgds,
Aleesya
Posted
Updated 12-May-11 16:55pm
v2
Comments
Karwa_Vivek 20-May-11 3:07am    
Got the Answer !

All you need is to call the crystal report page on 'select' click. Pass on the unique ID of that record to that page such that you can query the DB for the data related to it to be shown in report.

Have a look at these articles to get equipped with knowledge needed for it:
Dynamic Crystal Reports Viewing[^]
Dynamic Crystal Report with C#[^]

Few features step-by-step:
Introductions to Crystal Reports in .NET[^]
Step by Step Creation of Crystal Report using its Features Group, Graph, Cross-Tab and Sub Report[^]
Crystal Reports in ASP.NET[^]

Read and try!
 
Share this answer
 
Comments
Reena Aleesya 13-May-11 1:44am    
Hi,
Most of the link that u give i already tested in my side..but still not solve my problem..
May this will Solve Your problem.
As Per What I did
I have two forms Form1 and Form2
Form1 has Got the CR viewer and Form2 A gridview With Select button .I will also State that how I have Added The gridview button and Coulumns here .In Form2
I wrote a function to Display the Data from Db and to show it in the GridView Like :
Public Sub dataDisp()
        Dim sd As New SqlDataAdapter("Select * from Product", Mycon.con())
        Dim dt As New DataTable
        sd.Fill(dt)
        If dt.Rows.Count > 0 Then
            dGview.DataSource = dt

            Dim dgButtonColumn As New DataGridViewButtonColumn
            dgButtonColumn.HeaderText = ""
            dgButtonColumn.UseColumnTextForButtonValue = True
            dgButtonColumn.Text = "Select"
            dgButtonColumn.Name = "Select"
            dgButtonColumn.ToolTipText = "Select"
            dgButtonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader
            dgButtonColumn.FlatStyle = FlatStyle.System
            dgButtonColumn.DefaultCellStyle.BackColor = Color.Gray
            dgButtonColumn.DefaultCellStyle.ForeColor = Color.White
            dGview.Columns(0).Visible = False
            dGview.Columns.Add(dgButtonColumn)
        End If
    End Sub


After That i call This Function On the FormLoad Event or you Can take A button to Call This Function to Load the Data in the GridView.
Here I have Used A database table named "Product"
And then under dGview_CellContentClick Event checked that if Select button is Pressed Like :
Private Sub dGview_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dGview.CellContentClick
       If sender.Columns(e.ColumnIndex).Name = "Select" Then
           Form1.Show()
       End If
   End Sub


And if the Select Button is Pressed Call the Form1 or Say the Form Containing the CR viewer

And Now how to Load the report So, here Also I used a Function To Extract the Data form Db and to load it in the Report Like:
Private Sub MyReportCRYSTAL()

        Dim sd As New SqlDataAdapter("Select * from Product where Product_id='" & Form2.dGview.SelectedCells.Item(0).Value & "'", Mycon.con())
        Dim dt As New DataTable
        sd.Fill(dt)
        If dt.Rows.Count > 0 Then
            Dim pr As New ProductReport()
            pr.SetDataSource(dt)
            CrystalReportViewer1.ReportSource = pr
            CrystalReportViewer1.RefreshReport()
        End If
    End Sub

Here ProductReport is the CrystalReport what i ihave Designed taking the Fields from the Table Product
Call This Function On the Form Load Event.So that whenever You click the Select Button this Form opens and the Required Report also get loaded on the form load
Also I assume that You have the Id Field in the gridview which I am passing in the where Clause of the Select Query as "Form2.DataGridViewName.SelectedCells.Item(0).Value"
myCon is the Connection Class.
That's All.Try This Will Work Fine
 
Share this answer
 
Comments
Karwa_Vivek 20-May-11 5:39am    
The Above Procedure
is for Windows Form application.
Implement It as Per your need
rifayee 17-Oct-12 7:01am    
can u explain me the same process in web application...actually i am developing a web application.in that web application i am placing gridview and select option,,if i select the particular row,the particular row will be displayed in the crystal report..actually i have a problem to display that to crystal report..thanks in advance

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