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 126433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:19:01+00:00 2026-05-11T05:19:01+00:00

I have a bunch of dropdownlists which I populate from an xml file using

  • 0

I have a bunch of dropdownlists which I populate from an xml file using linq. I’ve tried the following to populate them and it somehow works, the only problem is that when an element is missing e.g. subtitle I get an empty space in the dropdownlist. Also I don’t get to have the distinct values of each dropdownlist but instead all values. See code below

 var feeds = (from item in doc.Descendants('item')                       select new                      {                          channel = (string)item.Element('channel') ?? null,                          specialtoken = (string)item.Element('specialtoken') ?? null,                          subchannel = (string)item.Element('subchannel') ?? null,                          subtitle = (string)item.Element('subtitle') ?? null,                      }).ToList().Distinct();           cboChannel.DataSource = feeds;         cboChannel.DataBind();          cboSpecialToken.DataSource = feeds;         cboSpecialToken.DataBind();          cboSubChannel.DataSource = feeds;         cboSubChannel.DataBind();          cboSubtitle.DataSource = feeds;         cboSubtitle.DataBind();         ...And so on.... 

Is there a better way than to split each value item into a seperate query e.g. ?

Cheers, Chris

var specialtoken = (from item in doc.Descendants('item')                      select new                      {                          specialtoken = (string)item.Element('specialtoken') ?? null,                      }).ToList().Distinct();   var channel= (from item in doc.Descendants('item')                      select new                      {                          channel = (string)item.Element('channel') ?? null,                      }).ToList().Distinct(); etc. etc. 
  • 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. 2026-05-11T05:19:02+00:00Added an answer on May 11, 2026 at 5:19 am

    I think the easiest way is to keep the original query but then do a sub query for each of the drop downs that ensures there is a value in the item they care about.

    cboChannel.DataSource = feeds.Where(x => !String.IsNullOrEmpty(x.channel)).ToList(); 

    I find this to be much more concise

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which is meant to populate a dropdown with a
Have a bunch of classes which I need to do serialize and deserialize from/to
I have bunch of data objects that I populate after getting data from a
I have bunch of strings, some of which are fairly long, like so: movie.titles
We have bunch of Domain Entities which should be rendered to an html format,
I have a bunch of files in a folder checked out from a repository.
I have a bunch of buttons that have a tapGestureRecognizer linked to them, and
I have bunch of web document and want to remove the html tags from
I have bunch of files and very file has a header of 5 lines.
I have bunch of temporal data which I want to convert to RDF format.

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.