Using values from hyperlink column in a query string

Last post 08-05-2003 2:23 AM by adec. 6 replies.

Sort Posts:

  • Using values from hyperlink column in a query string

    08-02-2003, 7:55 PM
    • Member
      170 point Member
    • steo009
    • Member since 07-05-2003, 7:05 PM
    • Posts 34
    Hi All!

    I just made a column in my datagrid a hyperlink column but I can't seem to use those values in the column in a query string anymore. Before I just used e.items[1].text to get it but thats not working anymore since I guess its now a hyperlink not plain text. How can I get the actual text of the hyperlink? Any help would be great!

    Thanks :)
  • Re: Using values from hyperlink column in a query string

    08-02-2003, 10:32 PM
    • Star
      11,397 point Star
    • SushilaSB
    • Member since 06-18-2002, 5:05 AM
    • Posts 2,265
    In case you are using HyperlinkColumn as

    <asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server">
    <Columns>
    <asp:HyperLinkColumn HeaderText="ID" DataNavigateUrlField="ID"
    DataNavigateUrlFormatString="link.aspx?id={0}"
    DataTextField="ID"></asp:HyperLinkColumn>
    </Columns>
    </asp:DataGrid>



    You can write
    Response.Write(Request.queryString("id"))

    Is this the way you are trying it
    or are you having Hyperlink as <asp:hyperlink runat=server.... >
    Sushila Bowalekar Patel
    Visual ASP/ASP.NET MVP
    http://weblogs.asp.net/sushilasb
  • Re: Using values from hyperlink column in a query string

    08-04-2003, 3:34 AM
    • Member
      170 point Member
    • steo009
    • Member since 07-05-2003, 7:05 PM
    • Posts 34
    Hmmm. But that only allows you to pass one parameter right? I tried to use multiple parameters but that doesn't work. Someone mentioned the use of an asp template column. That should be ok, but how do you pass another value in the same row in the same query string? The above example throws an index error if i tried {1}.
  • Re: Using values from hyperlink column in a query string

    08-04-2003, 4:26 AM
    • Star
      12,495 point Star
    • adec
    • Member since 06-15-2002, 10:12 AM
    • Malmoe, Sweden
    • Posts 2,491
    Remember that the HyperlinkColumn can be found during the ItemDataBound Event. You are surely familiar with how to use this Event Handler, so I'll provide an example of code to use for the Item and Alternating ListItemTypes:

    Private Sub dgrdProducts_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgrdProducts.ItemDataBound
    Dim item As ListItemType = e.Item.ItemType

    If item = ListItemType.Item Or item = ListItemType.AlternatingItem Then
    Dim hl As HyperLink = e.Item.Cells(0).Controls(0)

    hl.NavigateUrl = "bogus.aspx?prodid=" & e.Item.DataItem("ProductID") & "&supplid=" & e.Item.DataItem("SupplierID")

    End If

    End Sub

    The HL-Column is made up of Hyperlinks, so you'll need to find them. In my example, The first Control of the first Cell is a Hyperlink, as my Hyperlink Column is my First Column. You may now add as many arguments as you like to your hyperlink.
    Regards

    Andre Colbiornsen
    ---------------------------------
    Seventh Day
    Råbygatan 1A,
    SE-223 61 Lund
    Sweden
    Mob.: +46-(0)708-97 78 79
    Mail: info@seventhday.se
    --------------------------------
  • Re: Using values from hyperlink column in a query string

    08-04-2003, 4:34 AM
    • Member
      170 point Member
    • steo009
    • Member since 07-05-2003, 7:05 PM
    • Posts 34
    Hey thanks guys. It works! :)

    most grateful
  • Re: Using values from hyperlink column in a query string

    08-05-2003, 12:42 AM
    • Member
      375 point Member
    • catcyc
    • Member since 06-20-2003, 12:07 AM
    • Posts 75
    dear adec,
    i got the problem in using hyperlink in datagrid. Can you please teach me how to solve this problem, which i encounter the error-Input string was not in a correct format, when i click on the hyperlink.

    i enclosed herewith my code for your reference.

    <asp:datagrid id="MessageBoardRepeater" runat="server">
    <Columns>
    <asp:TemplateColumn HeaderStyle-Width="7%" HeaderText="Case No">
    <ItemTemplate>
    <asp:HyperLink text='<%# DataBinder.Eval(Container.DataItem, "title") %>' NavigateUrl= 'Thread.aspx?id=<%# DataBinder.Eval(Container.DataItem, "threadId") %>' Runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>

    thank you very much indeed.


    regards,
    Catcyc

  • Re: Using values from hyperlink column in a query string

    08-05-2003, 2:23 AM
    • Star
      12,495 point Star
    • adec
    • Member since 06-15-2002, 10:12 AM
    • Malmoe, Sweden
    • Posts 2,491
    Try this:

    <asp:datagrid id="MessageBoardRepeater" runat="server">
    <Columns>
    <asp:TemplateColumn HeaderStyle-Width="7%" HeaderText="Case No">
    <ItemTemplate>
    <asp:HyperLink text='<%# DataBinder.Eval(Container.DataItem, "title") %>' NavigateUrl= '<%# "Thread.aspx?id=" & DataBinder.Eval(Container.DataItem, "threadId") %>' Runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>
    Regards

    Andre Colbiornsen
    ---------------------------------
    Seventh Day
    Råbygatan 1A,
    SE-223 61 Lund
    Sweden
    Mob.: +46-(0)708-97 78 79
    Mail: info@seventhday.se
    --------------------------------
Page 1 of 1 (7 items)