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?

1 Answer 1

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 <%#

Sign up to request clarification or add additional context in comments.

4 Comments

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?
So assuming your dataset variable is ds. someValue = ds.tables[0'].rows[1]["IMEI"]? BTW you were right about the last parenthesis :)
@Melanie my apologies I overlooked that you were referring to an asp:net hyperlink.
Thanks much, Dalorzo!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.