Link to home
Start Free TrialLog in
Avatar of jtrapat1
jtrapat1

asked on

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.
john
working hyperlinkfield code:
<asp:HyperLinkField 
        HeaderText="ID"
        AccessibleHeaderText="none"
        ItemStyle-HorizontalAlign="Center" 
        ItemStyle-Wrap="False"
        ItemStyle-Width="10%" 
        Target="_blank" 
        DataTextField="InvoiceNum" 
  DataNavigateUrlFormatString="http://allegany/reportserver?/federalsurplus/fspInvoice&rs:Command=Render&InvoiceNum={0}"
        DataNavigateUrlFields="InvoiceNum"
        SortExpression="InvoiceNum" >
<ItemStyle HorizontalAlign="Center" Wrap="False" Width="10%"></ItemStyle>
      </asp:HyperLinkField>

Open in new window

Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

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)
Avatar of jtrapat1
jtrapat1

ASKER

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:
OnRowDataBound="gvResults_RowDataBound"

how can i fix this error?
thanks
John
forgot to attach the error image-
1.gif
ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You were absolutely right!
that worked great -
thanks
John