?
Solved

ASP.NET Datagrid show more than 1 column

Posted on 2007-11-13
5
Medium Priority
?
727 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
[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
  • 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 2000 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

Industry Leaders: 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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

771 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