Go Premium for a chance to win a PS4. Enter to Win


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

Posted on 2006-06-14
Medium Priority
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
  • 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 http://www.c-sharpcorner.com/Code/2003/May/AddingDataGridColumnToCal.asp 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 500 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataColumnClassExpressionTopic.asp

Author Comment

ID: 16904637
LVL 12

Expert Comment

ID: 16904650
Glad to help :)

/signing off from MS Tech Ed

Featured Post

Independent Software Vendors: 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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

926 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