当前位置: 代码迷 >> ASP.NET >> ListItem数组有关问题
  详细解决方案

ListItem数组有关问题

热度:6976   发布时间:2013-02-25 00:00:00.0
ListItem数组问题
C# code
        ListItem[] schlist = new ListItem[db.GetTable<schInfo>().Count()];        for (int i = 0; i < schlist.Length; i++)        {            foreach (var s in db.GetTable<schInfo>())            {                schlist[i].Text = s.schCode + "  " + s.schName;                schlist[i].Value = s.schCode;            }            schCode.Items.Add(schlist[i]);        }        DataBind();

  我在运行到schlist[i].Text = s.schCode + " " + s.schName;这一句时,提示我未将对象引用设置到对象的实例。请各位帮忙解决一下

------解决方案--------------------------------------------------------
ListItem[] schlist = db.GetTable<schInfo>()
.Cast<schInfo>().Select(x => new ListItem() { Text = x.schCode + " " + x.schName, Value = x.schCode}).ToArray();
DataBind();