Search code examples
asp.netgridviewdynamic-data

ASP.NET Repeat Dynamic Data Main Menu Horizontally?


The default ASP.NET Dynamic Data template by default uses a GridView to display the menu repeating vertically. This doesn't look particularly 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.


Solution

  • 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.