C# ASP.NET GridView中新增一行,嵌套一个GridView

//Parent GridView
DataTable dt_Parent = new DataTable ();
GridView gv_Parent = new GridView ();
gv_Parent.DataSource = dt_Parent ;
gv_Parent.DataBind();
//Child GridView
DataTable dt_Child = new DataTable ();
GridView gv_Child = new GridView ();
gv_Child.DataSource = dt_Child ;
gv_Child.DataBind();
//新增一行将Child加到Parent中
GridViewRow DetailsRow = new GridViewRow(l_index, -1, DataControlRowType.DataRow, DataControlRowState.Normal);	//l_index 要Add的行索引
TableCell HeaderCell = new TableCell();
DetailsRow.Cells.Add(HeaderCell);	//在新的一行中加一个空的单元格
TableCell DataCell = new TableCell();
DataCell.Attributes["colspan"] = (gv_Child.Columns.Count - 1).ToString();	//该单元格所占列数(合并)

DataCell.Controls.Add(gv_Child);	//在第二个单元格加入Child GridView
DetailsRow.Cells.Add(DataCell);
gv_Parent.Controls[0].Controls.AddAt(l_index + 2, DetailsRow);	//将新增的行加入到Parent GridView中
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值