0

I have an ASP.Net page with a GridView. In one of the GridView cells there's a HyperLink control and its NavigateURL property is set like so:

NavigateUrl='<%# "~/telecom/SmartPhoneInventory.aspx?IMEI=" +  Eval("IMEI") %>'

There's a RadioButtonList (rblDeviceType) on this page (not in the GridView) with four values. I want to add another querystring to the HyperLink's NavigateURL so that:

NavigateUrl='<%# "~/telecom/SmartPhoneInventory.aspx?IMEI=" +  Eval("IMEI") + "&devicetype=" + rblDeviceType.SelectedValue %>'

This is of course not correct syntax. Is there a way to do this?

Melanie
  • 3,021
  • 6
  • 38
  • 56

1 Answers1

1

Try this:

In your html

<a href='<%= string.Format("~/telecom/SmartPhoneInventory.aspx?IMEI={0}&devicetype=", this.someValue, rblDeviceType.SelectedValue) %>'>
        Hello World
    </a>

or in your html:

<asp:HyperLink runat="server"
        NavigateUrl='' ID="demoLink">
            Hello World
        </asp:HyperLink>

and then in your codebehind:

demoLink.NavigateUrl= string.Format("~/telecom/SmartPhoneInventory.aspx?IMEI={0}&devicetype=",this.someValue,rblDeviceType.SelectedValue)

Regarding

'someValue'

Which you present as Eval("IMEI") in your sample code since your code is not part of the Grid you will need to get this from either a control directly, session, viewstate or server side variable. Your code sample does not allow me to understand where is the original source of this value.

Try this in your code behind:

public partial class _Default : Page
{
    public string someValue = "Hello World";

Using string.Format and <%= instead of <%#

Dalorzo
  • 19,834
  • 7
  • 55
  • 102
  • IMEI is a column in a dataset which is bound to the GridView in the code behind. I've tried IMEI, "IMEI" and Eval("IMEI") using your syntax, but I just get an error message: The server tag is not well formed. BTW, I think you need a closed parenthesis after SelectedValue, right? – Melanie Jan 22 '14 at 19:02
  • So assuming your dataset variable is ds. someValue = ds.tables[0'].rows[1]["IMEI"]? BTW you were right about the last parenthesis :) – Dalorzo Jan 22 '14 at 19:55
  • @Melanie my apologies I overlooked that you were referring to an asp:net hyperlink. – Dalorzo Jan 22 '14 at 20:05
  • 1
    Thanks much, Dalorzo! – Melanie Jan 23 '14 at 16:06