2011-11-01 38 views
2

在我的ASPX頁面我有這樣的:

<h3> 
    <asp:HyperLink runat="server" 
     NavigateUrl="<%$ Resources:Path, Article%>" 
     Text='<%# Eval("title") %>' /> 
</h3> 

對於NavigateUrl屬性我想指定像

NavigateUrl="<%$ Resources:Path, Article%>?id=4" 

一個ID但是,當我做到這一點的表達不是由ASP解析器進行的。

我該怎麼做?

+0

這傷害了我的眼睛 –

+0

@GlennFerrieLive。?是的,我也是,你有更好的辦法嗎? – Tuizi

+0

我會合作另一種方法。意思是,定義鏈接programmatica LLY。希望工作 –

回答

2

不要在標記中這樣做。這裏有一個服務器控件 - 給它一個ID(比如,ID="NavigationLink",然後做這樣的事情在你的cs文件:

void Page_Load(object sender, EventArgs e) 
{ 
    // I'm guessing that "4" was just an example here, so fill that piece in with a function you can call to create the proper ID. 
    NavigationLink.NavigateUrl = Properties.Resources.Path + Properties.Resources.Article + "?id=4" 
} 

編輯:我假設當你說<%$ Resources:Path, Article%>那你想引用你的資源文件中PathArticle項,但經過進一步思考,這是很難告訴你在做什麼,你能更具體在這裏

1

您可以在類後面的代碼中定義一個受保護的函數,並從標記中調用它。就像這樣:

<h3> 
    <asp:HyperLink runat="server" 
     NavigateUrl="<%# GetNavigateUrl(Eval("ID")) %>" <%-- Passing an ID as a parameter for example --%> 
     Text='<%# Eval("title") %>' /> 
</h3> 

後面的代碼:

// Again, idObj is just an example. Any info from the data item can be passed here 
protected string GetNavigateUrl(object idObj) 
{ 
    int id = (int)idObj; 
    string urlFromResources = // retrieving the url from resources 
    return urlFromResources + '?ID=' + id; 
} 
0

嘗試的String.Format ...

<% =String.Format({0}?id={1}, Request.ApplicationPath, 4) %> 

它看起來像你混合其他語言到這個(JavaScript的?)。

此外,不要忘記給你的服務器端控件一個ID。

相關問題