0

我有一个带有 GridView 的 ASP.Net 页面。在其中一个 GridView 单元格中有一个 HyperLink 控件,其 NavigateURL 属性设置如下:

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

此页面上有一个 RadioButtonList (rblDeviceType)(不在 GridView 中),有四个值。我想向 HyperLink 的 NavigateURL 添加另一个查询字符串,以便:

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

这当然不是正确的语法。有没有办法做到这一点?

4

1 回答 1

1

试试这个:

在你的html

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

或在您的html

<asp:HyperLink runat="服务器"
        NavigateUrl='' ID="demoLink">
            你好世界
        </asp:超链接>

然后在你的codebehind

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

关于

'someValue'

Eval("IMEI")由于您的代码不是网格的一部分,因此您在示例代码中呈现的内容需要直接从控件、会话、视图状态或服务器端变量中获取。您的代码示例不允许我了解该值的原始来源在哪里。

在后面的代码中试试这个:

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

使用string.Formatand<%=代替<%#

于 2014-01-22T18:17:42.273 回答