Solved

ASP.NET Datagrid show more than 1 column

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
ASP Repeater control - onl;y show if flag is true 7 23
IEnumerable<T> to a List<T> 8 55
asp Google Map 2 65
Running powershell scripts from ASP.NET 6 60
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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