Solved

How do I make a gridview have multiple columns?

Posted on 2006-07-11
7
321 Views
Last Modified: 2008-01-09
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
Comment
Question by:jbrahy
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:valrog
ID: 17084384
In the item template you could put a table, or you can create two <asp:template> fields
0
 

Expert Comment

by:cjmackenzie
ID: 17084646
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
 
LVL 1

Author Comment

by:jbrahy
ID: 17085047
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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 3

Expert Comment

by:valrog
ID: 17085090
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
 
LVL 1

Author Comment

by:jbrahy
ID: 17085273
I need the paging, does the repeater have that?
0
 
LVL 3

Accepted Solution

by:
valrog earned 500 total points
ID: 17085349
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
 
LVL 1

Author Comment

by:jbrahy
ID: 17085512
thanks! that's exactly what I was looking for!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
convert html to string 6 34
ASP.net Show "please wait " message as page loads 2 42
jquery progress bar 3 43
Question about JQuery and asp.net 3 27
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question