首页新闻找找看学习计划

view state存值问题

0
悬赏园豆:5 [待解决问题]

页面代码中    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?

但是它又好像是有时候又不报错,有时候突然报错。

灬丶的主页 灬丶 | 初学一级 | 园豆:12
提问于:2017-02-15 09:36
< >
分享
所有回答(1)
0

完整的代码贴出来。可能的原因是(List<PayPlanEntity>)和ViewState["PlanList"]2个对象所在的appdomain不一致。所以不能强制转换

czd890 | 园豆:7984 (大侠五级) | 2017-02-15 12:36

什么意思,可以说的通俗点吗?

支持(0) 反对(0) 灬丶 | 园豆:12 (初学一级) | 2017-02-15 12:37

  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);
                }
            }
        }
    }

支持(0) 反对(0) 灬丶 | 园豆:12 (初学一级) | 2017-02-15 13:36

@灬丶: 

http://www.cnblogs.com/cyq1162/p/6212200.html

参考这个错误

支持(0) 反对(0) czd890 | 园豆:7984 (大侠五级) | 2017-02-15 15:55

怎么解决啊,我都不知道怎么改!!!!!!

支持(0) 反对(0) 灬丶 | 园豆:12 (初学一级) | 2017-02-16 14:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册