Solved

How do I make a gridview have multiple columns?

Posted on 2006-07-11
7
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net mvc , views, hidden values ? 2 26
Broken .resx file generating errors 18 44
Validation for Passport expiry in asp.net 2 32
Shared Service Environment 2 54
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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