Inserting multiple columns of a datatable as a single column of a datagrid in ASP.NET

Posted on 2006-06-14
Last Modified: 2012-06-27
Can we insert multiple columns of a datatable as a single column of a datagrid in ASP.NET?
Could you let me know how?

Question by:balabommala
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
  • 4
  • 2
LVL 12

Expert Comment

ID: 16904463
Sure you can. Either do it in the SQL query:

select firstname +', ' + lastname from names

Or do it with a column expression. See for an example on expressions (The new datacolumn part)

Author Comment

ID: 16904503
Thanks for your quick reply.
I want the data columns to be added to the next line in the datagrid column
like this:

123 Peter Street
Chesapeake VA

The above 3 lines are three columns in the table. But i wnat to show them as a single column in the datagrid as above.

LVL 12

Accepted Solution

TheMegaLoser earned 125 total points
ID: 16904554
The SQL Case (note, column and table names are just invented since I dont know yours)

select adress +'<BR>' + city +'<BR>' + zipcode from companies

.NET case coming soon
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!

LVL 12

Expert Comment

ID: 16904600
I dont have access to a .NET environment atm but if you place a datagrid on a page, have a normal SQL query (selcet adress, zip, city) set the autogeneratecolumns property to false and add the following markup in the columns part of the datagrid I think it should work:

<asp:DataColumn HeaderText="Address" Expression="address + '<BR>' + city + '<BR' + zip">

For more information on expressions, see

Author Comment

ID: 16904637
LVL 12

Expert Comment

ID: 16904650
Glad to help :)

/signing off from MS Tech Ed

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

710 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