Thursday, March 29, 2012

pass parameter in hyperlink

Hi

I am displaying the results of a query in a datalist. There are 2 fields returned with one an icon set as a hyperlink as follows:

Smile [:)]
name

When someone clicks on the icon I would like the name parameter to be passed to a new page to be used in a new query. Can someone please point me in the right direction.

Matt

The simplest way of doing this is to append the name as a query string variable, e.g.

<a href="http://links.10026.com/?link=http://someurl.com?name=xyz">...</a>


Thanks for the quick response. My code looks as follows:

<ItemTemplate>

<asp:HyperLink ID="Hyperlink1" runat="server" NavigateUrl="~/Login.aspx"><asp:Image ID="Image1" runat="server" ImageUrl='<%# SetUrl(Eval("status")) %>' ImageAlign="Middle" /></asp:HyperLink><br />
<asp:Label ID="term_idLabel" runat="server" Text='<%# Eval("term_id") %>' Font-Names="Arial" Font-Size="Small" ForeColor="White"></asp:Label><br />
<br />
</ItemTemplate
Which displays my data as:

Smile [:)] Big Smile [:D]
name1 name2

If the user clicks on name1's icon I'd like to pass name1 as the parameter. How do I access this term_idLabel instance?
You'll want to change the NavigateUrl property in HyperLink1 so the term_id is evaluated and passed as a parameter. Try this:

NavigateUrl='<%# Eval("term_id", "~/Login.aspx?name={0}") %>'
The string will be formatted with the value for term_id replacing the {0}.

0 comments:

Post a Comment