簡體   English   中英

快捷服務器端代碼塊

[英]shortcut server side code blocks

我正在asp.net頁面上工作,我需要向超鏈接的href添加可選參數。 參數值在代碼后面。

這是超鏈接:

<a href='FileView.aspx?fid=<%#Eval("FileOrFolderID") %>&uid=<%=UserID %> <%=(ProfileType.HasValue && ProfileId.HasValue?"&profiletype=" + (int)ProfileType.Value + "&profileid=" + ProfileId.Value:"") %>'
                                        <%#Convert.ToBoolean(Eval("IsFolder")) ? "style='display:none;'" : "style='display:block;'" %>
                                        id="aDownLoad">
                                        <%# Eval("Name").ToString().HE()%></a>

我要添加:

<%=(Convert.ToBoolean(Eval("IsFolder")) ? "" :  "&id=" + CurrentID) %>

這樣看起來像這樣:

<a href='FileView.aspx?fid=<%#Eval("FileOrFolderID") %>&uid=<%=UserID %> <%=(Convert.ToBoolean(Eval("IsFolder")) ? "" :  "&id=" + CurrentID) %> <%=(ProfileType.HasValue && ProfileId.HasValue?"&profiletype=" + (int)ProfileType.Value + "&profileid=" + ProfileId.Value:"") %>'
                                        <%#Convert.ToBoolean(Eval("IsFolder")) ? "style='display:none;'" : "style='display:block;'" %>
                                        id="aDownLoad">
                                        <%# Eval("Name").ToString().HE()%></a>

但是給出了這個錯誤:

An exception of type 'System.InvalidOperationException' occurred in System.Web.dll but was not handled in user code

Additional information: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

請提出解決此問題的方法

僅當您的控件綁定到數據源時才可以使用Eval和Bind,但實際情況並非如此。 使用服務器控件:

<asp:HyperLink runat="server" ID="link" />

並在后面的代碼上設置它的NavigationUrl屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM