Link to home
Start Free TrialLog in
Avatar of balabommala
balabommala

asked on

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

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.
Avatar of TheMegaLoser
TheMegaLoser
Flag of Sweden image

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)
Avatar of balabommala
balabommala

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of TheMegaLoser
TheMegaLoser
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Thanks.
Glad to help :)

/signing off from MS Tech Ed