我有以下HTML代码,我试图转换为ASP.net控件:
<ul>
<li class='active'><a href='about_us.aspx'>ABOUT US</a></li>
<li><a href="mission.aspx">MISSION</a></li>
<li class='has-sub'><a href='#'>LEADERSHIP</a>
<ul>
<li><a href='#'>President</a></li>
<li><a href='#'>Medical Director</a></li>
<li><a href='#'>Board of Directors</a></li>
<li><a href='#'>Key Administrators</a></li>
</ul>
</li>
<li><a href='history.aspx'>HISTORY</a></li>
<li><a href='community_support.aspx'>COMMUNITY SUPPORT</a></li>
</ul>
我将它转换为ASP.net,如下所示:
<asp:BulletedList ID="bListMenu" runat="server" DisplayMode="HyperLink">
<asp:ListItem class="active" Value="about_us.aspx">ABOUT US</asp:ListItem>
<asp:ListItem Value="mission.aspx">MISSION</asp:ListItem>
<asp:ListItem class="has-sub" Value="#">LEADERSHIP
<asp:BulletedList ID="bListMenuSub" runat="server" DisplayMode="HyperLink">
<asp:ListItem Value="#">President</asp:ListItem>
<asp:ListItem Value="#">Medical Director</asp:ListItem>
<asp:ListItem Value="#">Board of Directors</asp:ListItem>
<asp:ListItem Value="#">Key Administrators</asp:ListItem>
</asp:BulletedList>
</asp:ListItem>
<asp:ListItem Value="history.aspx">HISTORY</asp:ListItem>
<asp:ListItem Value="community_support.aspx">COMMUNITY SUPPORT</asp:ListItem>
</asp:BulletedList>
当我访问该页面时,我收到以下错误:
Parser Error Message: The 'Text' property of 'asp:ListItem' does not allow child objects.
Source Error:
Line 9: <asp:ListItem Value="#">Board of Directors</asp:ListItem>
Line 10: <asp:ListItem Value="#">Key Administrators</asp:ListItem>
Line 11: </asp:BulletedList>
Line 12: </asp:ListItem>
Line 13: <asp:ListItem Value="history.aspx">HISTORY</asp:ListItem>
Source File: /website/includeNav/aboutUsNav.inc Line: 11
答案 0 :(得分:2)
如何从BulletedList Web Server Control读取,BulletedList控件可以显示列表项,如下所示:
无论如何,您可以轻松地完成任务,而不是使用通用转发器:
<asp:Repeater ID="repeater" EnableViewState="False" runat="server" OnItemDataBound="myItemDataBound">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><%# Eval("nome") %>
<asp:BulletedList ID="bulletedList" runat="server"></asp:BulletedList>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
并填充ItemDataBound事件中的bulletedList:
protected void myItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataRowView row = e.Item.DataItem as DataRowView;
if (null == row)
return;
DataSet1.table1Row currentRow = row.Row as DataSet1.table1Row ;
if (currentRow != null)
{
BulletedList bList = e.Item.FindControl("bulletedList") as BulletedList;
bList.Items.Add("Foo");
}
}