页面代码中 public List<PayPlanEntity> PlanList
{
get { return (List<PayPlanEntity>)ViewState["PlanList"]; }
set { ViewState["PlanList"] = value; }
}
执行selectChanged事件时红色位置出现“[A]System.Collections.Generic.List`1[PayPlanEntity] cannot be cast to [B]System.Collections.Generic.List`1[PayPlanEntity]. Type A originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.”看不懂,list里面是页面中的临时实体,这个事件是gridview里面的。是不是view state不能存class?
但是它又好像是有时候又不报错,有时候突然报错。
完整的代码贴出来。可能的原因是(List<PayPlanEntity>)和ViewState["PlanList"]2个对象所在的appdomain不一致。所以不能强制转换
什么意思,可以说的通俗点吗?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindPayGrid(out list);
PlanList = list;
}
} private void BindPayGrid(out List<PayPlanEntity> list1)
{
IList<PayPlanEntity> list = new List<PayPlanEntity>();
// IList<Project> list = IoCContainer.Get<IProjectDao>().Select().Where(s => s.Number == RequestProjectNumber).ToList();
if (DesignReplyId != null)
{
if (DesignReplyId.Values.Contains(DesignReplyType.计划模块设计批复.GetValue().ToString()))
{
foreach (KeyValuePair<int, string> item in DesignReplyId)
{
if (item.Value == "1")
{
PayPlanEntity plan = new PayPlanEntity();
plan.ProjectNumber = RequestProjectNumber;
plan.DesignReplyId = item.Key;
plan.Type = DesignReplyType.计划模块设计批复;
plan.PayType = "设计";
PayPlanEntity plan1 = new PayPlanEntity();
plan1.ProjectNumber = RequestProjectNumber;
plan1.DesignReplyId = item.Key;
plan1.Type = DesignReplyType.计划模块设计批复;
plan1.PayType = "施工";
PayPlanEntity plan2 = new PayPlanEntity();
plan2.ProjectNumber = RequestProjectNumber;
plan2.DesignReplyId = item.Key;
plan2.Type = DesignReplyType.计划模块设计批复;
plan2.PayType = "监理";
list.Add(plan);
list.Add(plan1);
list.Add(plan2);
}
}
}
if (DesignReplyId.Values.Contains(DesignReplyType.工程模块设计批复.GetValue().ToString()))
{
foreach (KeyValuePair<int, string> item in DesignReplyId)
{
if (item.Value == "2")
{
PayPlanEntity plan = new PayPlanEntity();
plan.ProjectNumber = RequestProjectNumber;
plan.DesignReplyId = item.Key;
plan.Type = DesignReplyType.工程模块设计批复;
plan.PayType = "设计";
PayPlanEntity plan1 = new PayPlanEntity();
plan1.ProjectNumber = RequestProjectNumber;
plan1.DesignReplyId = item.Key;
plan1.Type = DesignReplyType.工程模块设计批复;
plan1.PayType = "施工";
PayPlanEntity plan2 = new PayPlanEntity();
plan2.ProjectNumber = RequestProjectNumber;
plan2.DesignReplyId = item.Key;
plan2.Type = DesignReplyType.工程模块设计批复;
plan2.PayType = "监理";
list.Add(plan);
list.Add(plan1);
list.Add(plan2);
}
}
}
if (DesignReplyId.Values.Contains(DesignReplyType.切块资金模块设计批复.GetValue().ToString()))
{
foreach (KeyValuePair<int, string> item in DesignReplyId)
{
if (item.Value == "4")
{
PayPlanEntity plan = new PayPlanEntity();
plan.ProjectNumber = RequestProjectNumber;
plan.DesignReplyId = item.Key;
plan.Type = DesignReplyType.切块资金模块设计批复;
plan.PayType = "设计";
PayPlanEntity plan1 = new PayPlanEntity();
plan1.ProjectNumber = RequestProjectNumber;
plan1.DesignReplyId = item.Key;
plan1.Type = DesignReplyType.切块资金模块设计批复;
plan1.PayType = "施工";
PayPlanEntity plan2 = new PayPlanEntity();
plan2.ProjectNumber = RequestProjectNumber;
plan2.DesignReplyId = item.Key;
plan2.Type = DesignReplyType.切块资金模块设计批复;
plan2.PayType = "监理";
list.Add(plan);
list.Add(plan1);
list.Add(plan2);
}
}
}
if (DesignReplyId.Values.Contains(DesignReplyType.集团管模块设计批复.GetValue().ToString()))
{
foreach (KeyValuePair<int, string> item in DesignReplyId)
{
if (item.Value == "3")
{
PayPlanEntity plan = new PayPlanEntity();
plan.ProjectNumber = RequestProjectNumber;
plan.DesignReplyId = item.Key;
plan.Type = DesignReplyType.集团管模块设计批复;
plan.PayType = "设计";
PayPlanEntity plan1 = new PayPlanEntity();
plan1.ProjectNumber = RequestProjectNumber;
plan1.DesignReplyId = item.Key;
plan1.Type = DesignReplyType.集团管模块设计批复;
plan1.PayType = "施工";
PayPlanEntity plan2 = new PayPlanEntity();
plan2.ProjectNumber = RequestProjectNumber;
plan2.DesignReplyId = item.Key;
plan2.Type = DesignReplyType.集团管模块设计批复;
plan2.PayType = "监理";
list.Add(plan);
list.Add(plan1);
list.Add(plan2);
}
}
}
}
list1 = new List<PayPlanEntity>();
list1 = list.ToList();
gvPay.DataSource = list;
gvPay.DataBind();
}
protected void piContract_SelectedChanged(object sender, EventArgs e)
{
int row = ((GridViewRow)((PopupInput)sender).NamingContainer).RowIndex;
PopupInput piContract = gvPay.Rows[row].FindControl("piContract") as PopupInput;
HyperLink hyStartPlan = gvPay.Rows[row].FindControl("hyStartPlan") as HyperLink;
Label lblPayType = gvPay.Rows[row].FindControl("lblPayType") as Label;
Label lblInfo = gvPay.Rows[row].FindControl("lblInfo") as Label;
lblInfo.Visible = false;
hyStartPlan.Visible = true;
for (int i = 0; i < PlanList.Count; i++)
{
if (i == row)
{
PayPlan data = IoCContainer.Get<IPayPlanDao>().Select().Where(s => s.ProjectNumber == RequestProjectNumber && s.DesignReplyId == PlanList[i].DesignReplyId && s.Type == PlanList[i].Type && s.PayPlanType.GetText() ==lblPayType.Text).FirstOrDefault();
if (data != null)
{
hyStartPlan.Visible = false;
}
hyStartPlan.NavigateUrl = string.Format("~/pages/pay-plan/edit.aspx?ProjectNumber={0}&DesignReplyId={1}&ContractId={2}&PayType={3}&DesignReplyType={4}&RowIndex={5}",
RequestProjectNumber, PlanList[i].DesignReplyId, ContractCodeDic[i.ToString()], lblPayType.Text.ToString().ToEnumByText<PayType>().GetIndex(), PlanList[i].Type.GetIndex(),row);
}
}
}
}
@灬丶:
http://www.cnblogs.com/cyq1162/p/6212200.html
参考这个错误
怎么解决啊,我都不知道怎么改!!!!!!