Answer: This can be achieved any of the two ways.
You can combine these two database fields in the template column of the gridview as shown below:
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="Name">
<itemtemplate>
<%# Container.DataItem("EmpID") %>, <%# Container.DataItem("Name") %>
</itemtemplate>
</asp:TemplateColumn>
</Columns>
</asp:GridView>
Other way of doing the same is to perform operation at database side. Retrieve the combined value as some column and bind the same with the databound column of the gridview.
Database side(SQL):
Select empid + ‘ : ‘ + name as name from emps;
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="Name">
</Columns>
</asp:GridView>
More preferable way is the second one as it will be less combursome.
Asked In: Many Interviews |
Alert Moderator