Solved

How do I make a gridview have multiple columns?

Posted on 2006-07-11
7
303 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now