有人可以對此有所瞭解我的NameValueCollection返回的是Length屬性而不是名稱和值可以讓我看看我在這裏做錯了什麼。我無法爲下拉列表設置DataTextField或DataValueField,它只是給了我一個長度。NameValueCollection返回長度屬性,而不是名稱值
public NameValueCollection GetDisplayForumGroups()
{
using (CMSEntities db = new CMSEntities())
{
var forums = (from x in db.Forums where x.ParentID == null select new { Name = x.Title, Value = x.ForumID });
NameValueCollection collection = new NameValueCollection();
foreach (var forum in forums)
{
collection.Add(forum.Name, forum.Value.ToString());
}
return collection;
}
}
public Dictionary<string, int> GetDisplayForumGroups()
{
using (CMSEntities db = new CMSEntities())
{
Dictionary<string, int> forums = (from x in db.Forums where x.ParentID == null select x).ToDictionary(x => x.Title, x => x.ForumID);
return forums;
}
}
您向我們展示了錯誤的代碼;設置DropDownList屬性的代碼在哪裏?如果您看到長度而不是名稱/值,則表示您設置了錯誤。 – 2012-02-13 00:26:45