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

I am using gridview with 23 columns.The first column i have template field with link button(Edit) option, second column is the primary id column, the remaining columns are necessary columns.After 5th column, 7 columns comes under common column name like A,the remaining number of columns comes under some other common column name like B. The common column name A and B are merge successfully but the link button(Edit) is not working correctly. Without using merge option the link button(Edit) is working correctly.
What can i do for that?

Update:

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                GridViewRow gvRow = e.Row;
                if (gvRow.RowType == DataControlRowType.Header)
                {
                    if (gvRow.Cells[0].Text == "Edit")
                    {
                        /*The following lines is very important concept, whenever the first cell content is remove, the next cell content comes in that position.
                          For example the 0th position content is Edit and 1st position content is Lite Id
                          If i remove 0th position content Edit, the 1st position content Lite Id, comes to the 0th position. So we need to add 6 lines
                         */

                        gvRow.Cells.Remove(gvRow.Cells[0]);
                        gvRow.Cells.Remove(gvRow.Cells[0]);
                        gvRow.Cells.Remove(gvRow.Cells[0]);
                        gvRow.Cells.Remove(gvRow.Cells[0]);
                        gvRow.Cells.Remove(gvRow.Cells[0]);
                        gvRow.Cells.Remove(gvRow.Cells[0]);
                        gvRow.Cells.Remove(gvRow.Cells[0]);

                        GridViewRow gvHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);

                        TableCell headerCell0 = new TableCell()
                        {
                            Text = "Edit",
                            HorizontalAlign = HorizontalAlign.Center,
                            RowSpan = 2,
                            
                        };
                        TableCell headerCell1 = new TableCell()
                        {
                            Text = "lite_id",
                            HorizontalAlign = HorizontalAlign.Center,
                            RowSpan = 2
                        };
                        TableCell headerCell2 = new TableCell()
                        {
                            Text = "Quarter",
                            HorizontalAlign = HorizontalAlign.Center,
                            RowSpan = 2
                        };
                        TableCell headerCell3 = new TableCell()
                        {
                            Text = "Contract No",
                            HorizontalAlign = HorizontalAlign.Center,
                            RowSpan = 2
                        };
                        TableCell headerCell4 = new TableCell()
                        {
                            Text = "BP Name",
                            HorizontalAlign = HorizontalAlign.Center,
                            RowSpan = 2
                        };
                        TableCell headerCell5 = new TableCell()
                        {
                            Text = "City",
                            HorizontalAlign = HorizontalAlign.Center,
                            RowSpan = 2
                        };
                        TableCell headerCell6 = new TableCell()
                        {
                            Text = "Target",
                            HorizontalAlign = HorizontalAlign.Center,
                            ColumnSpan = 7
                        };
                        TableCell headerCell7 = new TableCell()
                        {
                            Text = "Achievement",
                            HorizontalAlign = HorizontalAlign.Center,
                            ColumnSpan = 9
                        };

                        gvHeader.Cells.Add(headerCell0);
                        gvHeader.Cells.Add(headerCell1);
                        gvHeader.Cells.Add(headerCell2);
                        gvHeader.Cells.Add(headerCell3);
                        gvHeader.Cells.Add(headerCell4);
                        gvHeader.Cells.Add(headerCell5);
                        gvHeader.Cells.Add(headerCell6);
                        gvHeader.Cells.Add(headerCell7);

                        GridView1.Controls[0].Controls.AddAt(0, gvHeader);
                    }
                }
            }
            catch (Exception ex)
            {
                errorLabel.Text = ex.ToString();
            }
        }
Posted
Updated 14-Jul-15 0:57am
v3
Comments
DamithSL 14-Jul-15 4:18am    
how you do the merging columns? update the question with related code

1 solution

Hi,
Finally i got what i want. I used page selection option in the grid view to obtain my desired output. Thanks for you all.
 
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