首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ListItem数组有关问题

2012-09-23 
ListItem数组问题C# codeListItem[] schlist new ListItem[db.GetTableschInfo().Count()]for (int i

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


热点排行