在c#中合并gridview单元格和链接按钮 [英] Merge gridview cells and linkbutton in c#

查看:66
本文介绍了在c#中合并gridview单元格和链接按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用带有23列的gridview。第一列我有模板字段,带有链接按钮(编辑)选项,第二列是主要ID列,其余列是必需的列。在第5列之后,7列在公共列名下像A一样,剩余的列数在一些其他常见的列名下,如B.公共列名A和B合并成功但是链接按钮(编辑)无法正常工作。没有使用合并选项,链接按钮(编辑)工作正常。

我该怎么办?



更新:



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:

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();
            }
        }

推荐答案



最后我得到了我想要的。我在网格视图中使用了页面选择选项来获得我想要的输出。谢谢大家。
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.


这篇关于在c#中合并gridview单元格和链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆