Solved

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

Posted on 2006-06-14
6
235 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 47
Re-position the objects 7 96
SQL best practice question 3 36
ASP.NET 5 Templates 2 65
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…
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 …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now