Click here to Skip to main content
15,904,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have gridview like
ASP.NET
<asp:GridView ID="gvShowRequests" runat="server" AllowPaging="true" 
    AutoGenerateColumns="false" Width="60%"
    CssClass="gvRows" AllowSorting="false" GridLines="Both" 
    BorderColor="Black" PagerStyle-CssClass="pager"
    OnPageIndexChanging="gvShowRequests_PageIndexChanging" 
    onselectedindexchanged="gvShowRequests_SelectedIndexChanged">
    <RowStyle CssClass="gvRows" />
    <AlternatingRowStyle CssClass="gvRowsalt" />
    <Columns>
        <asp:BoundField DataField="Id" HeaderText="Id" Visible="false" />
        <asp:BoundField DataField="Name" HeaderText="Application" />                                    
        <asp:BoundField DataField="UserName" HeaderText="User Name" />
        <asp:BoundField DataField="Type" HeaderText="Request Type" />
        <asp:BoundField DataField="Status" HeaderText="Request Status" />
        <asp:BoundField DataField="FirstName" HeaderText="First Name" />
        <asp:BoundField DataField="LastName" HeaderText="Last Name" />
        <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID" />
        <asp:BoundField DataField="AddedOn" HeaderText="Added On" />
    </Columns>
</asp:GridView>



What I want is : Display First Name, Last Name and EmployeeID in one column under header Name
How can I do it?
Posted
Updated 4-Jan-12 11:22am
v2

change query as

SQL
select id,(fname + '' +lname) as Name from tablename


and now bind as
C#
<asp:boundfield datafield="Name" headertext="Application" sortexpression="Name" xmlns:asp="#unknown" />
 
Share this answer
 
v2
Comments
tejashri.gandhi 4-Jan-12 22:49pm    
Thank Uma...This is the simplest and quickest thing I could do..
Please try this code to merge cell of your grid view
i thing it may help you

public static void MergeRows(GridView gridView)
    {
        for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
        {
            GridViewRow row = gridView.Rows[rowIndex];
            GridViewRow previousRow = gridView.Rows[rowIndex + 1];

            for (int i = 0; i < row.Cells.Count; i++)
            {
                if (row.Cells[i].Text == previousRow.Cells[i].Text)
                {
                    row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 : 
                                           previousRow.Cells[i].RowSpan + 1;
                    previousRow.Cells[i].Visible = false;
                }
            }
        }
    }
 
Share this answer
 
v2
 
Share this answer
 
v2
Comments
Prasad_Kulkarni 4-Jan-12 7:15am    
good one..
Try
DataTable.Merge Method [^] which is used to merge the specified DataTable with the current DataTable.
C#
// Merge new data into the modified data.
   table1.Merge(modifiedTable, true);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900