Solved

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

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

Thanks.
0
Comment
Question by:balabommala
  • 4
  • 2
6 Comments
 
LVL 12

Expert Comment

by:TheMegaLoser
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)
0
 

Author Comment

by:balabommala
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
02305

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.

Thanks
0
 
LVL 12

Accepted Solution

by:
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
0
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!

 
LVL 12

Expert Comment

by:TheMegaLoser
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">
</asp:DataColumn>


For more information on expressions, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataColumnClassExpressionTopic.asp
0
 

Author Comment

by:balabommala
ID: 16904637
Thanks.
0
 
LVL 12

Expert Comment

by:TheMegaLoser
ID: 16904650
Glad to help :)

/signing off from MS Tech Ed
0

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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