Problem with hyperlink to another page while passing parameter

Rate It (1)

Last post 06-15-2009 5:01 AM by Qin Dian Tang - MSFT. 4 replies.

Sort Posts:

  • Problem with hyperlink to another page while passing parameter

    06-10-2009, 1:04 PM
    • Member
      46 point Member
    • GMann
    • Member since 02-22-2007, 6:18 PM
    • Posts 204

    Hi;

    I am trying to link to another page through the RowDataBind event like so :

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

    Dim tempUID As String = Session("UID")

    Dim holdHLnk As HyperLink = New HyperLink

        holdHLnk = TryCast(e.Row.FindControl("HyperLink1"), HyperLink)

    If e.Row.RowType = DataControlRowType.DataRow Then

               If tempUID = "aaaaaaa" Then

                                  holdHLnk.NavigateUrl = String.Format("SpecialPage.aspx?ID={0}", ID)

               Else

                                   holdHLnk.NavigateUrl = String.Format("InputPage.aspx?id={0}", ID)

                End If

    End If

    End Sub

    I get a error message when I click on the hyperlink button in the gridview.

        Input string was not in a correct format.

     I tried stepping through the code but every thing looks ok.

    As far as my web page code goes here is the template column for the hyperlink :

       

    <div id="grd1" style="font-family: Verdana; font-size: small;" language="javascript" >

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"

    AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ObjectDataSource4"

    EmptyDataText="There were no records found" Font-Size="Small" Style="font-size: 8pt;

    font-family: Verdana" PageSize="20">

    <Columns>

    <%-- <asp:HyperLinkField NavigateUrl="Tasks_Input.aspx" DataNavigateUrlFields="ID" DataNavigateUrlFormatString="Tasks_Input.aspx?ID={0}" Text="Update" />--%>

    <asp:TemplateField>

    <ItemTemplate>

          <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ID", "tasks_Input.aspx?ID={0}")%>' Text="Update">

         </asp:HyperLink>

    </ItemTemplate>

    </asp:TemplateField>

     Thanks for any insights !

     

  • Re: Problem with hyperlink to another page while passing parameter

    06-10-2009, 2:23 PM
    • All-Star
      27,490 point All-Star
    • PeteNet
    • Member since 01-21-2009, 6:15 PM
    • Posts 3,892

     when you step through the code do you see a value being assigned to ID? where have you assigned it?

    you'd need something like this, right? : e.Row.Cells(yourIndex).Text etc

    Regards,
    Peter
  • Re: Problem with hyperlink to another page while passing parameter

    06-10-2009, 3:17 PM
    • Member
      46 point Member
    • GMann
    • Member since 02-22-2007, 6:18 PM
    • Posts 204

    Thanks

    Yes, the ID is a part of the link.

     In which statement would I need to include this ?

    In here ?   holdHLnk.NavigateUrl = String.Format("SpecialPage.aspx?ID={0}", ID) 

    There is a DataNavigateUrlFields to pass in the web page version  

    <asp:HyperLinkField NavigateUrl="Tasks_Input.aspx" DataNavigateUrlFields="ID" DataNavigateUrlFormatString="Tasks_Input.aspx?ID={0}" Text="Update" />

    but I thought that this was the ID in the String.Format(xxxxx, ID) ?

    I did not notice a DataNavigateUrlFields property in the Hyperlink Class

    Could you clarify this for me ?

    I did find this other message with the same issue except he isn't passing a parm.

    <Hyperlink>, OnClick event, and changing the NavigateUri

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7d481397-20b9-4864-bc30-877252c75e84/

    I think that they are using a link button but mine should work with just the hyperLink control.

  • Re: Problem with hyperlink to another page while passing parameter

    06-10-2009, 3:40 PM
    • All-Star
      27,490 point All-Star
    • PeteNet
    • Member since 01-21-2009, 6:15 PM
    • Posts 3,892

     

    Dim ID As String = e.Row.Cells(yourDatabaseIDColumnhere).Text

    put this before you do this: If tempUID = "aaaaaaa" Then

     for the other query you had...I found an example for you

    Regards,
    Peter
  • Re: Problem with hyperlink to another page while passing parameter

    06-15-2009, 5:01 AM
    Answer

    Hi GMann,

    Try this:

    <asp:HyperLink ID="HyperLink1" runat="server" Text="Update"></asp:HyperLink>

    Then handle RowDataBound event of GridView:

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim hl As HyperLink = DirectCast(e.Row.FindControl("HyperLink1"), HyperLink)
            If Session("UID").ToString() = "aaaaaaa" Then
                hl.NavigateUrl = "SpecialPage.aspx?ID=" & DirectCast(e.Row.DataItem, DataRowView)("ID").ToString()
            Else
                hl.NavigateUrl = "InputPage.aspx?id=" & DirectCast(e.Row.DataItem, DataRowView)("ID").ToString()
            End If
        End If
    End Sub

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (5 items)