Solved

ASP.NET Datagrid show more than 1 column

Posted on 2007-11-13
5
719 Views
Last Modified: 2010-05-18
Hi Experts,

Im brand new to ASP.NET so forgive me if this is a really simple question.

I have a recordset from a sql database and using asp:datalist can output the records fine.

How do I add columns to the output. At the moment all the data comes out in a single column.
I have 5 fields to output and would like the 5 fields to output in columns and then repeat in rows.

This is the code I have so far.

<asp:DataList
AlternatingItemStyle-BackColor="Gainsboro"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
CellSpacing="0"
DataKeyField="Surname" DataSource="<%# Get_Students1.DefaultView %>"
EditItemStyle-BackColor="lightgreen"
Font-Names="Verdana"
Font-Size="8pt"
GridLines="Both"
HeaderStyle-BackColor="#aaaadd"
ID="Datagrid" RepeatColumns="1" RepeatDirection="Vertical" RepeatLayout="Table"
runat="server"
Width="150px"> <HeaderTemplate> Items </HeaderTemplate>
<ItemTemplate>
<%# Get_Students1.FieldValue("GivenNames", Container) %>
<%# Get_Students1.FieldValue("Surname", Container) %>
<%# Get_Students1.FieldValue("DateOfBirth", Container) %>
<%# Get_Students1.FieldValue("Gender", Container) %>
<%# Get_Students1.FieldValue("School", Container) %>
</ItemTemplate>
</asp:DataList>

The containers that are all togerther at the moment is the ones I want seperated into columns.

Thanks for your help
0
Comment
Question by:nikdonovanau
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Aurora27
ID: 20276646
I have used Datalist, but I dont get this question. You can check this:

http://www.ondotnet.com/pub/a/dotnet/2003/03/10/datalist.html

If you want to combine columns, its got to be done in the query itself.

Thank you.

Charu.
0
 
LVL 1

Author Comment

by:nikdonovanau
ID: 20276684
Thanks for that Charu.

My output above gives me this.

-------------
a b c d e f |
-------------

What I am after is

--------------------
a | b | c | d | e | f |
--------------------

I can get it by using the following code (adding </td><td> tags manually)

<ItemTemplate>
<%# Get_Students1.FieldValue("GivenNames", Container) + "</td><td>" %>
<%# Get_Students1.FieldValue("Surname", Container)+ "</td><td>" %>
<%# trim(left(Get_Students1.FieldValue("DateOfBirth", Container),10))+ "</td><td>"
 %>
<%# Get_Students1.FieldValue("Gender", Container)+ "</td><td>" %>
<a href="#">Edit</a>
</ItemTemplate>

But im sure this is not the way to do it?
0
 
LVL 16

Accepted Solution

by:
anoyes earned 500 total points
ID: 20276822
Nik,
In the case of a DataList, yes, this is how you should do it.  A datalist just wraps a table around whatever you supply in the <ItemTemplate> tag.  If you want it to completely generate it for you, use a GridView.

Info on DataList: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/datalist.aspx
Info on GridView: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/gridview.aspx
0
 
LVL 1

Author Comment

by:nikdonovanau
ID: 20276845
GridView. Thanks very much, thats what I was looking for.
0
 
LVL 3

Expert Comment

by:Aurora27
ID: 20276965
Hehe.. :D I didnt know you were looking for Gridview. That gives you easy editing capabilities too. Try it. I wud prefere DatagRid anyday. :)

Charu.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

12 Experts available now in Live!

Get 1:1 Help Now