Displaying two columns from a database table as one column on a website is often needed. A typical example is where we want to show a person's first name and last name in one column in a datagrid. The easiest way of doing this is to create an SQL statement that builds a new display column containing both database columns.
- Skill level:
Things you need
- SQL Editor
Open SQL Editor.
Create an SQL statement to concatenate (or join) both database table columns and output as one column called "FullName":
select FirstName +' '+LastName as FullName from users
Use the variable "FullName" where you require it in the DataGrid:
<asp:DataGrid runat="server" AutoGenerateColumns="False" ... >
<asp:TemplateColumn HeaderText="Name" > <ItemTemplate > <%# Container.DataItem("FullName") %> </ItemTemplate > </asp:TemplateColumn >
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for