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

  • Home
  • SEARCH
  • 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 9013599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:18:32+00:00 2026-06-16T03:18:32+00:00

I have an empty listbox on .aspx page lstbx_confiredLevel1List I am generating two lists

  • 0

I have an empty listbox on .aspx page

lstbx_confiredLevel1List

I am generating two lists programatically

List<String> l1ListText = new List<string>(); //holds the text 
List<String> l1ListValue = new List<string>();//holds the value linked to the text

I want to load lstbx_confiredLevel1List list box on .aspx page with above values and text. So i am doing following:

lstbx_confiredLevel1List.DataSource = l1ListText;
lstbx_confiredLevel1List.DataTextField = l1ListText.ToString();
lstbx_confiredLevel1List.DataValueField = l1ListValue.ToString();
lstbx_confiredLevel1List.DataBind();

but it does not load the lstbx_confiredLevel1List with l1ListText and l1ListValue.

Any ideas?

  • 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-06-16T03:18:33+00:00Added an answer on June 16, 2026 at 3:18 am

    Why don’t you use the same collection as DataSource? It just needs to have two properties for the key and the value. You could f.e. use a Dictionary<string, string>:

    var entries = new Dictionary<string, string>();
    // fill it here
    lstbx_confiredLevel1List.DataSource = entries;
    lstbx_confiredLevel1List.DataTextField = "Value";
    lstbx_confiredLevel1List.DataValueField = "Key";
    lstbx_confiredLevel1List.DataBind();
    

    You can also use an anonymous type or a custom class.

    Assuming that you have already these lists and you need to use them as DataSource. You could create a Dictionary on the fly:

    Dictionary<string, string> dataSource = l1ListText
               .Zip(l1ListValue, (lText, lValue) => new { lText, lValue })
               .ToDictionary(x => x.lValue, x => x.lText);
    lstbx_confiredLevel1List.DataSource = dataSource;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox on .aspx web page in which I am trying to
I have two list controls in my asp.net page and am populating the second
In a WPF page that I'm designing for my church, I have two ListBox
I am generating an Excel file through MATLAB and I have empty cells in
I have two asp:ListBox. The ID's are Authors and AuthorsSelected. Authors listbox is loaded
My scenario is this: I have two listbox's, one that contains all my database
I have a page that has several ListBox es that have some cascading filtering
I have a ListBox in a xaml page for a Windows Phone 7 app.
I have a listbox on my xaml form that I bound to a List(Of
Trying to fill the listbox programatically I have written the following code: protected override

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.