【发布时间】:2015-07-13 14:55:49
【问题描述】:
我收到这个错误
"加载视图状态失败。视图状态所在的控件树 正在加载的必须与用于保存的控制树匹配 上一个请求期间的视图状态。例如,当添加 动态控制,回发期间添加的控件必须匹配 在初始阶段添加的控件的类型和位置 要求。 "
当我尝试提交一个页面时,我在 GridView rowdatabound 上应用了一些逻辑来更改 RowSpan。在评论此事件时没有错误。
这里是代码:
int firstRow;
string previousCat;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var drv = e.Row.DataItem as QCParameters;
if (previousCat == drv.AuditTypeValue)
{
//If it's the same category as the previous one
//Increment the rowspan
if (GridView1.Rows[firstRow].Cells[0].RowSpan == 0)
{
GridView1.Rows[firstRow].Cells[0].RowSpan = 2;
GridView1.Rows[firstRow].Cells[5].RowSpan = 2;
}
else
{
GridView1.Rows[firstRow].Cells[0].RowSpan += 1;
GridView1.Rows[firstRow].Cells[5].RowSpan += 1;
}
//Remove the cell
if (e.Row.Cells.Count > 5)
e.Row.Cells.RemoveAt(5);
e.Row.Cells.RemoveAt(0);
}
else //It's a new category
{
e.Row.VerticalAlign = VerticalAlign.Top;
//Maintain the category in memory
previousCat = drv.AuditTypeValue;
firstRow = e.Row.RowIndex;
}
}
}
【问题讨论】: