dataGrid 多维表头,表头跨行跨列设计

 

dataGrid 其实就是一个HTML TABLE

想清楚这个以后,要设置多维表头就好办了

HTML代码

 <asp:DataGrid ID="DataGrid1" runat="server"
            onitemdatabound="DataGrid1_ItemDataBound">
        </asp:DataGrid>

然后绑定数据

protected void Page_Load(object sender, EventArgs e)
        {
            string strsql = "select EmpID, Name, BranchID, LoginID, Pwd, Sex, EmpCode, Email, OfficeTel from mrBaseInf";
            SqlConnection con = new SqlConnection("server=.;database=iOffice2009;uid=sa;pwd=sa");
            DataSet ds = new DataSet();
            SqlDataAdapter ter = new SqlDataAdapter(strsql, con);
            con.Open();
            ter.Fill(ds);
            con.Close();
            this.DataGrid1.DataSource = ds;
            DataGrid1.DataBind();
        }

接下来添加DataGrid1_ItemDataBoun事件

 protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType==ListItemType.Header)
            {
                e.Item.Cells[0].RowSpan = 2;
                e.Item.Cells[1].RowSpan = 2;
                e.Item.Cells[2].RowSpan = 2;
                e.Item.Cells[3].RowSpan = 2;
                e.Item.Cells[4].RowSpan = 2;
                e.Item.Cells[5].ColumnSpan = 4;
                e.Item.Cells[5].HorizontalAlign = HorizontalAlign.Center;
                e.Item.Cells[5].Text = "测试</td></tr><tr><td>列1</td><td>列2</td><td>列3</td><td>列4</td></tr>";
                e.Item.Cells[6].Visible = false;
                e.Item.Cells[7].Visible = false;
                e.Item.Cells[8].Visible = false;
               
            }
        }

效果图

 

 

 

转载于:https://www.cnblogs.com/lweasy/archive/2012/12/18/dataGrid.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值