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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:40:23+00:00 2026-06-01T20:40:23+00:00

I have a combobox that I bind to a list of objects with three

  • 0

I have a combobox that I bind to a list of objects with three properties: int a, int b, and string x. When bound I set DataTextField to x and DataValueField to a. What I want to do is get the value of b in the code-behind after the collection has been bound to the list. I do not want to use ViewState. Can I possibly use reflection? Something like this?

var dataSource = ddlTest.GetDataSource();
var newDataSource = dataSource.GetType().GetProperty("_dataSource", 
    BindingFlags.NonPublic | BindingFlags.Instance);
  • 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-01T20:40:25+00:00Added an answer on June 1, 2026 at 8:40 pm

    I’m not sure about this, but you might be able to add b as a custom attribute to the ListItem. Try something like this and see if it works:

    var table = new DataTable("TableName"); 
    
    //bind the dropdown to the result set
    dropDownList.DataSource = table;
    dropDownList.DataBind();
    
    //iterate through the datasource and add custom attributes for each item in the list
    table.AsEnumerable().ToList().ForEach(r => 
        dropDownList.Items.FindByValue(r.Field<int>("a").ToString()).Attributes["data-field"] = r.Field<int>("b").ToString());    
    

    If you’d prefer to use a regular foreach loop:

    foreach (DataRow row in table.Rows)
    {
        var item = dropDownList.FindByValue(row.Field<int>("a").ToString());
        if (item != null)
        {
            item.Attributes["data-value"] = row.Field<int>("b").ToString();
        }
    }
    

    If adding custom attributes doesn’t work and you don’t want to use ViewState, you might have to store both a and b in the value field, separated by a delimeter. This can be a pain because you’ll have to parse the items to get the values, but given your requirements that might be the best option if the custom attributes don’t work.

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

Sidebar

Related Questions

I have a DataTable (or Generic List) that I want to bind to 2
I have a combobox on my form that is bound to a generic list
I have a combo box that I want to bind to a list of
I have a small problem. I have a set of ComboBox's that are bound
I have a comboBox that is bound to a list of strings from my
Is it possible to bind a ComboBox to a list of objects, but have
I have a ComboBox that has its ItemsSource bound to a static List<CustomSettings> of
I have a ComboBox that I set up like this: this.cmbCustomerJob.DisplayMember = display; this.cmbCustomerJob.AutoCompleteMode
I have a ComboBox that I am populating with a list of parts for
I have a ComboBox that has the SelectedItem bound to the ViewModel. <ComboBox SelectedItem={Binding

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.