Hyperlinkfield report path passed in from code-behind.

I am displaying an asp:gridview of records with a linked list of results;
The first column is a hyperlinkfield of InvoiceNumber; which when the user clicks on it, launches a Reporting Services Report of details for that Invoice Number parameter;
Right now, I have the report path hard-coded and it works nice;
But I cant seem to pass the report server name/path in the code-behind.
Can this be done or do I have to use a linkbutton?

attached is my current code for the hyperlinkfield which works,
AND I am including the non-working code where I try to pass the report name path in the code-behind for the hyperlinkfield.  I add a RowDataBound event to my gridview and code a function in the code-behind.
Protected Sub gvResults_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvResults.RowDataBound
            Dim strURL As String
            Dim strPath As String

            strURL = ConfigurationManager.AppSettings("ReportURL").ToString
            strPath = ConfigurationManager.AppSettings("ReportPath").ToString
            strPath = strURL + strPath

            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim hl As HyperLink = TryCast(e.Row.Cells(0).Controls(0), HyperLink)
                hl.NavigateUrl = strPath
                hl.NavigateUrl = "fspInvoice&rs:Command=Render&InvoiceNum={0}" & gvResults.DataKeyNames(e.Row.RowIndex)(0)
            End If
        End Sub

Maybe I don't have the syntax correct but it seems like I have more control over the report and more properties available for the hyperlinkfield.
For example, with the hyperlinkfield, I have target="_blank" so that I can open SSRS report in a new window which helps with our application.
I dont know if that is available for the linkbutton.

thanks in advance.
working hyperlinkfield code:
        SortExpression="InvoiceNum" >
<ItemStyle HorizontalAlign="Center" Wrap="False" Width="10%"></ItemStyle>

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
The second line below overwrites the first line:

                hl.NavigateUrl = strPath
                hl.NavigateUrl = "fspInvoice&rs:Command=Render&InvoiceNum={0}" & gvResults.DataKeyNames(e.Row.RowIndex)(0)

Instead, do:

                hl.NavigateUrl = strPath & "fspInvoice&rs:Command=Render&InvoiceNum={0}" & gvResults.DataKeyNames(e.Row.RowIndex)(0)
jtrapat1Author Commented:
shaun kline-
thanks for the response-
I tried what you suggested but Im getting an error:
"Index was outside the bounds of the array. "
when I debug, i can mouse over and the strPath is correct;
and the DataKeyNames has the correct field name but not the value;
since this occurs when the gridview is being rendered, NOT even clicked on at this point.

In my definition for the gridview - i stripped out everything for the asp:hyperlinkfield and just added the ondataBound event to the definition like so:

how can i fix this error?
jtrapat1Author Commented:
forgot to attach the error image-
Shaun KlineLead Software EngineerCommented:
Instead of using DataKeyNames, try using DataKeys:

hl.NavigateUrl = strPath & "fspInvoice&rs:Command=Render&InvoiceNum={0}" & gvResults.DataKeys(e.Row.RowIndex)(0)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jtrapat1Author Commented:
You were absolutely right!
that worked great -
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.