• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

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>
0
jbrahy
Asked:
jbrahy
  • 3
  • 3
1 Solution
 
valrogCommented:
In the item template you could put a table, or you can create two <asp:template> fields
0
 
cjmackenzieCommented:
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>
0
 
jbrahyAuthor Commented:
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>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
valrogCommented:
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.
0
 
jbrahyAuthor Commented:
I need the paging, does the repeater have that?
0
 
valrogCommented:
The repeat and datalist controls do not have paging but the following tuturial will show you how to add paging to them.

http://aspnet.4guysfromrolla.com/articles/081804-1.aspx
0
 
jbrahyAuthor Commented:
thanks! that's exactly what I was looking for!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now