Solved

ASP.NET Datagrid show more than 1 column

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

18 Experts available now in Live!

Get 1:1 Help Now