Search code examples
asp.netlistviewnewlineitemtemplate

How to prevent ItemTemplate and AlternatingItemTemplate from creating newlines


In aspx, using either a ListView, Repeater, or any of the other standard controls that are listed under the visual studio 2010 data toolbox: My data source is simply a set of records made up of ID, title, first_name, last_name, degree. I am trying to print them on a single line (going to a newline when the end of a line is reached, not necessarily by a new record), however, the ItemTemplate and AlternatingItemTemplate seems to print each record as a newline. Is there a way to get rid of that automatic newline? (I tried ItemSeparatorTemplate, but that didn't work)

I don't think that it is necessary, but I figured that I'll just give you the code:

<asp:ListView ID="ListView2" runat="server" DataSourceID="AccessDataSource2">
     <ItemTemplate>
         <a href='#<%# Eval("ID") %>' /><%# Eval("title")%> <%# Eval("first_name")%> <%# Eval("last_name")%> <%# Eval("degree")%></a>
     </ItemTemplate>
     <AlternatingItemTemplate>
         <a href='#<%# Eval("ID") %>' /><%# Eval("title")%> <%# Eval("first_name")%> <%# Eval("last_name")%> <%# Eval("degree")%></a>
     </AlternatingItemTemplate>
</asp:ListView>

Solution

  • Use Datalaist and make RepeatDirection="Horizontal".

    <asp:DataList ID="datalist1" runat="server" RepeatDirection="Horizontal"></asp:DataList>