合并asp.net中的gridview列 [英] merge gridview columns in asp.net

查看:63
本文介绍了合并asp.net中的gridview列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





ASP.ner / VB.net / VS2010



i想要合并我的gridview中的列,其中所有四个单元格都是相同的。



有人可以帮我吗



谢谢

Joe

Hi,

ASP.ner / VB.net / VS2010

i would want to merge the column in my gridview where all four cells of a row are the same.

Could someone help me on this

thanks
Joe

推荐答案

试试这段代码。

一旦你跨过了表格单元格,我们应该删除其他人。

Try this code.
Once you spanned the table cell, we should remove others.
public partial class _Default : System.Web.UI.Page
    {
        private bool _alternate = false;

        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            ds.Tables.Add(new DataTable("Employee"));
            ds.Tables[0].Columns.Add("Id");
            ds.Tables[0].Columns.Add("Name");
            ds.Tables[0].Rows.Add("1", "Name1");
            ds.Tables[0].Rows.Add("1", "Name2");
            ds.Tables[0].Rows.Add("2", "Name3");
            ds.Tables[0].Rows.Add("2", "Name4");

            GridView1.DataSource = ds;
            GridView1.DataMember = "Employee";
            GridView1.DataBind();
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
        }

        void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (_alternate)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells.RemoveAt(1);
            }

            _alternate = !_alternate;
        }
    }


在DataBound事件中你可以设置范围



In the DataBound event you can set the span

gvRow.Cells[0].RowSpan


[ ^ ]应该可以帮助您入门。
This [^] should help you get started.


这篇关于合并asp.net中的gridview列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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