C# 如何在<;%…%内使用c代码&燃气轮机;asp.net页面上的标记?
我正在编写一个asp.net用户控件。它有一个属性,FutureReadingPage,以及绑定到它的两个控件:ObjectDataSource和一个Repeater。在中继器内部,我想显示一个带有href属性的超链接,该属性设置为C# 如何在<;%…%内使用c代码&燃气轮机;asp.net页面上的标记?,c#,asp.net,C#,Asp.net,我正在编写一个asp.net用户控件。它有一个属性,FutureReadingPage,以及绑定到它的两个控件:ObjectDataSource和一个Repeater。在中继器内部,我想显示一个带有href属性的超链接,该属性设置为进一步阅读页面+“?id=“+Eval(“id”)。我不知道如何在页面的标记中进行。我可以单独使用或,但我不知道如何将它们混合使用。试试这个(例如链接):试试这个: <%#String.Format("{0}?id={1}",FurtherReadingPage
进一步阅读页面+“?id=“+Eval(“id”)
。我不知道如何在页面的标记中进行。我可以单独使用
或
,但我不知道如何将它们混合使用。试试这个(例如链接):
试试这个:
<%#String.Format("{0}?id={1}",FurtherReadingPage, Id)%>
你可以这样做-
<asp:Hyperlink runat="Server" ID="hlLink" NavigateUrl='<%# FurtherReadingPage + "?Id=" + DataBinder.Eval(Container.DataItem, "Id") %>' />
您有两个不同的标签:
这混合了@Keith:你错了。我只是试着在一个中继器内进行双重检查,它工作正常。对不起,是的,
<% int id = int.Parse(Request["id"]); %>
<%=id %> <!-- note no ; -->
<!-- this is shorthand for: -->
<% Response.Write(id); %>
<%# Eval("id") %>
<!-- this could be inside a repeater or another control -->
<asp:Hyperlink runat="server" ID="demo"
NavigateUrl="page.aspx?id=<%# Eval("id") %>" />
<% //without this bind the <%# will be ignored
void Page_Load( object sender, EventArgs e ) {
demo.DataBind();
//or
repeaterWithManyLinks.DataBind();
}
%>