如何在后台动态的修改gridview某一列的标题
展开全部
gridview上加上 OnRowCreated="gdvFaultList_RowCreated"
后台方法里
protected void gdvFaultList_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//获取表头所在行的所有单元格
TableCellCollection tcHeader = e.Row.Cells;
//清除自动生成的表头
tcHeader.Clear();
tcHeader.Add(new TableHeaderCell());
tcHeader[0].RowSpan = 2;
tcHeader[0].Wrap = false;
tcHeader[0].Text = "姓名";
tcHeader.Add(new TableHeaderCell());
tcHeader[1].ColumnSpan= 2;
tcHeader[1].Wrap = false;
tcHeader[1].Text = "总标题";
tcHeader.Add(new TableHeaderCell());
tcHeader[2].RowSpan = 2;
tcHeader[2].Wrap = false;
tcHeader[2].Text = "年龄";
tcHeader.Add(new TableHeaderCell());
tcHeader[3].Wrap = false;
tcHeader[3].Text = "标题1";
tcHeader.Add(new TableHeaderCell());
tcHeader[4].Wrap = false;
tcHeader[4].Text = "标题2";
}
}
后台方法里
protected void gdvFaultList_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//获取表头所在行的所有单元格
TableCellCollection tcHeader = e.Row.Cells;
//清除自动生成的表头
tcHeader.Clear();
tcHeader.Add(new TableHeaderCell());
tcHeader[0].RowSpan = 2;
tcHeader[0].Wrap = false;
tcHeader[0].Text = "姓名";
tcHeader.Add(new TableHeaderCell());
tcHeader[1].ColumnSpan= 2;
tcHeader[1].Wrap = false;
tcHeader[1].Text = "总标题";
tcHeader.Add(new TableHeaderCell());
tcHeader[2].RowSpan = 2;
tcHeader[2].Wrap = false;
tcHeader[2].Text = "年龄";
tcHeader.Add(new TableHeaderCell());
tcHeader[3].Wrap = false;
tcHeader[3].Text = "标题1";
tcHeader.Add(new TableHeaderCell());
tcHeader[4].Wrap = false;
tcHeader[4].Text = "标题2";
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询