2
我需要從標記中設置用戶控件的屬性值。從ASP.NET標記中設置UserControl屬性值
我需要在標記中設置我的用戶控件中名爲「ItemIndex」的屬性。
由於某些不幸的原因,「<%:x%>」部分ItemIndex =「<%:x%>」未得到解決。
基本上ItemIndex的值變成「<%:x%>」而不是成爲x的實際值。
下面是代碼(請注意CAPS中的評論)。
<%@ Register TagPrefix="DDLControls" TagName="MainMenuItem" Src="~/Views/Header/MainMenuItemControl.ascx" %>
<div id="MainMenu">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<%
foreach (MenuItem mi in Model.Items)
{
string x = Model.Items.IndexOf(mi).ToString();
%>
<td>
<%= x %> <<-- THIS GETS RESOLVED TO 0,1,2,3,4,...
<DDLControls:MainMenuItem ItemIndex="<% x %>" runat="server" /> <<-- THIS DOESN'T GET RESOLVED
</td>
<%
}
%>
</tr>
</table>
</div>
是否有更多的東西需要與調用代碼做了什麼? – Reuben