Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7446313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:17:01+00:00 2026-05-29T12:17:01+00:00

Could someone shed some light on this my NameValueCollection returns the Length property instead

  • 0

Could someone shed some light on this my NameValueCollection returns the Length property instead of Name and Value could some show me what im doing wrong here. I can’t set the DataTextField or DataValueField for the dropdownlist it just gives me length.

    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;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:17:02+00:00Added an answer on May 29, 2026 at 12:17 pm

    You can’t bind directly to a NameValueCollection since it doesn’t provide a suitable enumerator. The standard enumerator enumerates through the keys only.

    Then again you shouldn’t be using a NameValueCollection for this in the first place, you should use the generic Dictionary unless you need multiple values per key (and even then there are better alternatives for most cases). There’s even a Linq method for automagically making a dictionary:

    Dictionary<string, int> forums = (from x
                                      in db.Forums
                                      where x.ParentID == null
                                      select x)
                                     .ToDictionary(x => x.Title, x => x.ForumID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would be really grateful if someone could shed some light on this for
Could someone shed some light on where this code is incorrect please <script> chrome.browserAction.onClicked.addListener(function(window)
Could someone please shed some light on this behaviour? It looks like Delphi SOAP
Could someone shed some light on why my WndProc method as implemented below isn't
Just wondering if someone could shed some light on a problem I'm having. The
I'm having a strange problem deserializing and was wondering if someone could shed some
Why doesn't Internet Explorer render this .css sprite menu i made? Could someone shed
I have been debugging this for awhile now, and I'm hoping someone could shed
Could someone please demystify interfaces for me or point me to some good examples?
Could someone supply some code that would get the xpath of a System.Xml.XmlNode instance?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.