How to pass value from gridview to crystal report

sbr7770

New member
Joined
Mar 2, 2007
Messages
3
Programming Experience
Beginner
I have a web page with a gridview that displays all of the equipment in the requested building. The last column in the gridview has a hyperlink to view the preventive maintenance history using a Crystal Report. The code works fine but my problem is I need to pass the eqiupment id from the gridview to the crystal report parameter. If I type in a literal equipment id in the code, the report receives the code and displays the correct report. I don't know how to refer to the equipment id in the gridview to pass it to the report. I have the gridview set up to pass the equipment id to the HistView page where the crystal report is located. it looks like this: HistView.aspx?eqid={0}. I have listed my code below. The equipment id I have typed in is 038-018. this is where I need to reference the eqid from the gridview. I have tried this line of code:
crParameterDiscreteValue.Value = " '" & HistView.aspx?eqid={0} & "' "
but vb underlines the Histview.aspx and says it is undefined.

The Gridview looks like this:

equip id view pm history
038-016 hyperlink to crystal report
038-017 hyperlink to crystal report
038-018 hyperlink to crystal report
many more......

Here's my code:

ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
Dim tbCurrent1 As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent1 As CrystalDecisions.Shared.TableLogOnInfo
' Create a report document instance to hold the report
Dim cr AsNew ReportDocument()
Try
' Load the report
cr.Load("g:\data\facilities\pm_history\pm_history.rpt")
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues AsNew ParameterValues()
Dim crParameterDiscreteValue AsNew ParameterDiscreteValue()
crParameterDiscreteValue.Value = "038-018"
crParameterFieldDefinitions = cr.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("eqid")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterFieldDefinitions = cr.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("eqid")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
' Set the connection information for all the tables used in the report
' Leave UserID and Password blank for trusted connection
ForEach tbCurrent1 In cr.Database.Tables
tliCurrent1 = tbCurrent1.LogOnInfo
With tliCurrent1.ConnectionInfo
.UserID = "afg"
.Password = "afg"
EndWith
tbCurrent1.ApplyLogOnInfo(tliCurrent1)
Next tbCurrent1
' Set the report source for the crystal reports
' viewer to the report instance.
CrystalReportViewer1.ReportSource = cr
Catch Exp As LoadSaveReportException
MsgBox("Incorrect path for loading report.", _
MsgBoxStyle.Critical, "Load Report Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
EndTry
EndSub

Thanks for any help you can provide.

SBR
 
If that should be a string link where the id value may change, it should be something like this:
VB.NET:
crParameterDiscreteValue.Value = " 'HistView.aspx?eqid={" & idvalue & "}' "
 
I copied HistView.aspx?eqid={" & idvalue & "} into my code but vb underlines idvalue and says that it's not declared.

Thanks,
SBR
 
How to pass value from gridview to crytal report

I guess that's where I'm lost. I thought the viewhist.aspx?eqid={0} was the variable. That's what is passed from the default.aspx where the gridview displays the equipment id's.

Thanks
SBR
 
Back
Top