views:

26

answers:

2

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.

+1  A: 

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

Ranhiru Cooray
That I understand. Can you show me what that might look like? Right now I add a datalist and nothing appears.
davemackey
Im Sorry. I think I must have understood you incorrectly. I explained on using a DataList when the data is in a DataSet or a DataTable. But the Dynamic Data template is a bit too complicated :(
Ranhiru Cooray
Thanks, you pointed me in the right direction. I've outlined the solution I came up with below.
davemackey
+1  A: 

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.

davemackey