Solved

ASP.NET Datagrid show more than 1 column

Posted on 2007-11-13
5
721 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

11 Experts available now in Live!

Get 1:1 Help Now