views:

696

answers:

1

I am looking for the best solution for my problem. I am currently using a asp.net gridview with a link in the first column and the id to the item it relates too.

Details href=.../page.aspx?ID=25

I have 3 hidden fields that I would like to bring with me to the next page.

I want the url to look something like this. Details href=.../page.aspx?ID=25&HDN1=3&HDN2=5&HDN3=76

I am able to set the values of the hidden text. I need to retrieve the values and add them to the url in the Details link.(onclick?). What is the best way to get this done??

+1  A: 

If these hidden fields are part of the databinding source collection then you can pass multiple parameters to a HyperLinkField GridView column. eg:

<asp:HyperLinkField DataNavigateUrlFields="id, field1, field2" DataNavigateUrlFormatString="/page.aspx?id={0}&hdn1={1}&hdn3={2}" />

Edit:

OK if it's client side, then you will have to do this via javascript.

I would add an onclick handler to each of your links:

<a href="details.aspx?id=123" onclick="detailsHandler(this.href); return false;" />

then a javascript function to handle the redirect:

function detailsHandler(href) {
    var hiddenField = document.getElementById('eleID').value;
    //get any other hidden fields and append them.
    href = href + "&amp;hnd1=" + hiddenfield;
    //then redirect to the revised url
    window.location = href;
}
DaRKoN_
How do I add this to each link on the page? Gridview complains that it does not have a public property named onclick
Jordan Johnson
$('.ItemLink').click(function(){ detailsHandler(this.href); return false;});
Jordan Johnson
If you're using the GridView HyperLinkField column then it doesn't have any event properties. You can either do it programatically (eg, hook into the OnRowDataBound event of the gridview, and modify each row as they are created) or what I would do is use a TemplateField instead, and then just use a normal anchor tag in it. (Or use the jQuery method mentioned above).
DaRKoN_