开发者

ASP.NET Repeat Dynamic Data Main Menu Horizontally?

开发者 https://www.devze.com 2023-01-06 07:32 出处:网络
The default ASP.NET Dynamic Data template by default uses a GridView to display the menu repeating vertically. This doesn\'t look p开发者_开发技巧articularly well. I\'m wondering if there is either (a

The default ASP.NET Dynamic Data template by default uses a GridView to display the menu repeating vertically. This doesn't look p开发者_开发技巧articularly well. I'm wondering if there is either (a) a way to get the gridview repeating horizontally or (b) use another control that allows horizontal repeating.


A DataList can be used :) You set an ItemTemplate to specify how the items should be displayed and set the RepeatDirection to Horizontal, bind it to your Dynamic data source and you are done :D

Additionally you can specify the number of columns to be repeated through the RepeatColumns attribute.

This page (scroll down towards the end) has got some examples on how to use a DataList

http://msdn.microsoft.com/en-us/library/7efxhktc.aspx


This is a simple process. In our code-behind file we have to wire up our Dynamic Data connection like so:

    Menu1.DataSource = visibleTables
    Menu1.DataBind()

Then we create a DataList like so:

<asp:DataList ID="Menu1" runat="server" 
      CellPadding="3" GridLines="Vertical" 
      HorizontalAlign="Center" CssClass="DDGridView" RepeatDirection="Horizontal"   
      ItemStyle-CssClass="td" HeaderStyle-CssClass="th" >
<ItemTemplate>
    <asp:DynamicHyperLink ID="HyperLink1" runat="server"><%# Eval("DisplayName")%></asp:DynamicHyperLink>
</ItemTemplate>
</asp:DataList>

You can see that I've utilized (temporarily) the css classes from the default gridview to provide uniform layout/display elements.

0

精彩评论

暂无评论...
验证码 换一张
取 消