gridview 表头值的问题
我做了一个gridview用户控件protectedvoidGridView1_RowCreated(objectsender,GridViewRowEventArgse...
我做了一个gridview用户控件
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
//合并表头相同单元格
if (e.Row.RowType == DataControlRowType.Header)
{
int j = 1;
for (int i = 0; i < e.Row.Cells.Count; i++)
{
string a = e.Row.Cells[i].Text;
//string str1 = ((LinkButton)e.Row.Cells[i].Controls[0]).Text;
if (i == e.Row.Cells.Count - 1)
{
e.Row.Cells[i].ColumnSpan = j;
break;
}
if (e.Row.Cells[i].Text == e.Row.Cells[i + 1].Text)
{
e.Row.Cells[i].Visible = false;
j++;
}
else
{
e.Row.Cells[i].ColumnSpan = j;
j = 1;
continue;
}
}
}
}
这样可以在每次加载的时候合并HeaderText一样的表头,但我开启GridView1.AllowSorting = true;排序功能以后 我就不能捕获到e.Row.Cells[i].Text的值,当GridView1.AllowSorting = false上为正常,这是为什么啊,求解。 展开
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
//合并表头相同单元格
if (e.Row.RowType == DataControlRowType.Header)
{
int j = 1;
for (int i = 0; i < e.Row.Cells.Count; i++)
{
string a = e.Row.Cells[i].Text;
//string str1 = ((LinkButton)e.Row.Cells[i].Controls[0]).Text;
if (i == e.Row.Cells.Count - 1)
{
e.Row.Cells[i].ColumnSpan = j;
break;
}
if (e.Row.Cells[i].Text == e.Row.Cells[i + 1].Text)
{
e.Row.Cells[i].Visible = false;
j++;
}
else
{
e.Row.Cells[i].ColumnSpan = j;
j = 1;
continue;
}
}
}
}
这样可以在每次加载的时候合并HeaderText一样的表头,但我开启GridView1.AllowSorting = true;排序功能以后 我就不能捕获到e.Row.Cells[i].Text的值,当GridView1.AllowSorting = false上为正常,这是为什么啊,求解。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询