Link to home
Start Free TrialLog in
Avatar of jbrahy
jbrahy

asked on

How do I make a gridview have multiple columns?

I've got this gridview and I need to make it have two columns, what should I change?

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
   AutoGenerateColumns="False" CellPadding="0" CellSpacing="0" CssClass="newstableposition"
   DataSourceID="WTDDataSource" EmptyDataText="<BR/><BR/>There are currently no artists."
   GridLines="None" HeaderStyle-Height="30px" HeaderStyle-HorizontalAlign="Left"
   HeaderStyle-VerticalAlign="Top" HeaderStyle-Wrap="false" RowStyle-HorizontalAlign="Left"
   RowStyle-VerticalAlign="Top" ShowFooter="True" Width="90%" >
   <PagerSettings Mode="Numeric" PageButtonCount="5" Position="TopAndBottom" />
   <PagerStyle CssClass="paginate" />
   <Columns>
      <asp:TemplateField>
         <ItemTemplate>
            <a href="/artist_buzz/artist_buzz_detail.aspx?artistID=<%# Eval("ArtistID")%>">
               <img alt="Artist Image" border="0" class="advisoryboardimgpad" src="<%# Eval("ContentServer") %>/images/artists/<%# Eval("ArtistThumbnailImage")%>" />
            </a>
            <br />
            <a href="/artist_buzz/artist_buzz_detail.aspx?artistID=<%# Eval("ArtistID")%>"><%# Eval("ArtistFirstName")%>&nbsp;<%# Eval("ArtistLastName")%></a><br />
            <span class="smallwhitetext10">
               <%# Eval("ArtistBandAffiliation")%>
            </span>
         </ItemTemplate>
      </asp:TemplateField>
   </Columns>
</asp:GridView>
Avatar of valrog
valrog

In the item template you could put a table, or you can create two <asp:template> fields
Is this what you want? NB it contains 2 template fields as suggested by valrog

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Temp.aspx.cs" Inherits="Temp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
   AutoGenerateColumns="False" CellPadding="0" CssClass="newstableposition"
   DataSourceID="WTDDataSource" EmptyDataText="<BR/><BR/>There are currently no artists."
   GridLines="None" HeaderStyle-Height="30px" HeaderStyle-HorizontalAlign="Left"
   HeaderStyle-VerticalAlign="Top" HeaderStyle-Wrap="false" RowStyle-HorizontalAlign="Left"
   RowStyle-VerticalAlign="Top" ShowFooter="True" Width="90%" >
   <PagerSettings PageButtonCount="5" Position="TopAndBottom" />
   <PagerStyle CssClass="paginate" />
   <Columns>
      <asp:TemplateField HeaderText="Column 1">
         <ItemTemplate>
            <a href="/artist_buzz/artist_buzz_detail.aspx?artistID=<%# Eval("ArtistID")%>">
               <img alt="Artist Image" border="0" class="advisoryboardimgpad" src="<%# Eval("ContentServer") %>/images/artists/<%# Eval("ArtistThumbnailImage")%>" />
            </a>
         </ItemTemplate>
     </asp:TemplateField>
     <asp:TemplateField HeaderText="Column 2">
         <ItemTemplate>
            <a href="/artist_buzz/artist_buzz_detail.aspx?artistID=<%# Eval("ArtistID")%>"><%# Eval("ArtistFirstName")%>&nbsp;<%# Eval("ArtistLastName")%></a><br />
            <span class="smallwhitetext10">
               <%# Eval("ArtistBandAffiliation")%>
            </span>
         </ItemTemplate>
      </asp:TemplateField>
   </Columns>
        <RowStyle HorizontalAlign="Left" VerticalAlign="Top" />
        <HeaderStyle Height="30px" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
</asp:GridView>
    </div>
    </form>
</body>
</html>
Avatar of jbrahy

ASKER

I've tried that but I get the same data in each column, I need the next result in the second column...

This currently prints out two columns but the data is the same, is there a way to do a recordset.movenext or something like that? I need the paging and I don't want to have to reinvent the wheel.


<asp:GridView  ID="GridView1" runat="server" AllowPaging="True" AllowSorting="False"
   AutoGenerateColumns="False" CellPadding="0" CellSpacing="0" CssClass="newstableposition"
   DataSourceID="WTDDataSource" EmptyDataText="<BR/><BR/>There are currently no artists."
   GridLines="None" HeaderStyle-Height="30px" HeaderStyle-HorizontalAlign="Left"
   HeaderStyle-VerticalAlign="Top" HeaderStyle-Wrap="false" RowStyle-HorizontalAlign="Left"
   RowStyle-VerticalAlign="Top" ShowFooter="True" Width="90%" >
   <PagerSettings PageButtonCount="5" Position="TopAndBottom" />
   <PagerStyle CssClass="paginate" />
   <Columns>
      <asp:TemplateField>
         <ItemTemplate>
            <a href="/artist_buzz/artist_buzz_detail.aspx?artistID=<%# Eval("ArtistID")%>">
               <img alt="Image of <%# Eval("ArtistFirstName")%> <%# Eval("ArtistLastName")%>" border="0"
                  class="advisoryboardimgpad" src="<%# Eval("ContentServer") %>/images/artists/<%# Eval("ArtistThumbnailImage")%>" />
            </a>
            <br />
            <a href="/artist_buzz/artist_buzz_detail.aspx?artistID=<%# Eval("ArtistID")%>">
               <%# Eval("ArtistFirstName")%>
               <%# Eval("ArtistLastName")%>
            </a>
            <br />
            <span class="smallwhitetext10">
               <%# Eval("ArtistBandAffiliation")%>
            </span>
         </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField>
         <ItemTemplate>
            <a href="/artist_buzz/artist_buzz_detail.aspx?artistID=<%# Eval("ArtistID")%>">
               <img alt="Image of <%# Eval("ArtistFirstName")%> <%# Eval("ArtistLastName")%>" border="0" class="advisoryboardimgpad" src="<%# Eval("ContentServer") %>/images/artists/<%# Eval("ArtistThumbnailImage")%>" />
            </a>
            <br />
            <a href="/artist_buzz/artist_buzz_detail.aspx?artistID=<%# Eval("ArtistID")%>">
               <%# Eval("ArtistFirstName")%>
               <%# Eval("ArtistLastName")%>
            </a>
            <br />
            <span class="smallwhitetext10">
               <%# Eval("ArtistBandAffiliation")%>
            </span>
         </ItemTemplate>
      </asp:TemplateField>
   </Columns>
   <RowStyle HorizontalAlign="Left" VerticalAlign="Top" />
   <HeaderStyle Height="30px" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
</asp:GridView>
If you are trying to make the gridview put two pictures side by side, then you are using the wrong control.  You may want to look into the repeater control.
Avatar of jbrahy

ASKER

I need the paging, does the repeater have that?
ASKER CERTIFIED SOLUTION
Avatar of valrog
valrog

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jbrahy

ASKER

thanks! that's exactly what I was looking for!