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

Ask A Question

Stats

  • Questions 281k
  • Answers 281k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Unfortunately, the first good framework class for this is the… May 13, 2026 at 3:53 pm
  • Editorial Team
    Editorial Team added an answer Try using the "Uses Unit Cleaner" Wizard from CnPack you… May 13, 2026 at 3:53 pm
  • Editorial Team
    Editorial Team added an answer HTTP has about the same overheads as FTP. An HTTP… May 13, 2026 at 3:53 pm

Related Questions

Preamble: I am using ASP.NET 3.5 and AJAXControlToolkit. I am trying to use the
I have the following code which is meant to populate a dropdown with a
I'm just playing with some linq and asp.net - absolute beginner so I'm not
Preamble I'm asking this question because even though I've read through a lot of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.