更新时间:2022-12-31 16:30:54
如何从的的BulletedList Web服务器控件,BulletedList控件可以显示列表项为下列之一:
反正你就可以轻松实现你的任务,而是使用一个共同的转发器:
< ASP:直放站ID =直放站的EnableViewState =假=服务器OnItemDataBound =myItemDataBound>
<&HeaderTemplate中GT;
< UL>
< / HeaderTemplate中>
<&ItemTemplate中GT;
<立GT;<%#的eval(诺姆)%>
< ASP:的BulletedList ID =的BulletedList=服务器>< / ASP:BulletedList中>
< /李>
< / ItemTemplate中>
< FooterTemplate>
< / UL>
< / FooterTemplate>
< / ASP:直放站>
和填充ItemDataBound事件中的BulletedList:
保护无效myItemDataBound(对象发件人,RepeaterItemEventArgs E)
{
DataRowView的行= e.Item.DataItem为DataRowView的;
如果(空==行)
返回; DataSet1.table1Row currentRow = row.Row为DataSet1.table1Row; 如果(currentRow!= NULL)
{
BulletedList中bList = e.Item.FindControl(的BulletedList)作为BulletedList中; bList.Items.Add(富);
}
}
I have the following HTML code which I am trying to convert to ASP.net control:
<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>
I converted it to ASP.net like this:
<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>
When I visit the page, i get the following error:
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
How you can read from BulletedList Web Server Control, the BulletedList control can display list items as any of the following:
Anyway you can easily achieve your task, using instead a common repeater:
<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>
And populate the bulletedList in ItemDataBound event:
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");
}
}