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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:37:58+00:00 2026-06-05T23:37:58+00:00

How to select value in combobox according to SQLDataReader value. ASP code: <asp:SqlDataSource ID=PREFERENCE_DS

  • 0

How to select value in combobox according to SQLDataReader value.

ASP code:

<asp:SqlDataSource ID="PREFERENCE_DS" runat="server" 
   ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionStringTEST %>" 
   SelectCommand="SELECT [ID], [NAME] FROM [OBJECTS] WHERE ([CLASSID] = @CLASSID) UNION ALL SELECT NULL, ' Нет'">
    <SelectParameters>
       <asp:Parameter DefaultValue="3" Name="CLASSID" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

<dx:ASPxComboBox ID="PREFERENCE" runat="server" SelectedIndex="0" Width="430px" 
   ClientInstanceName="preference" AutoPostBack="True" 
   DataSourceID="PREFERENCE_DS" TextField="NAME" TextFormatString="{0}" 
   ValueField="ID">
   <Columns>
      <dx:ListBoxColumn FieldName="ID" Visible="False" />
      <dx:ListBoxColumn Caption="Преференция" FieldName="NAME" />
   </Columns>
</dx:ASPxComboBox>

I try

PREFERENCE.Value = reader["PREFERENCE"];

and

if (reader["PREFERENCE"] != null)
   PREFERENCE.Text = reader["PREFERENCE"].ToString();
else
   PREFERENCE.SelectedIndex = PREFERENCE.Items.FindByValue(DBNull.Value).Index;

but it doesn’t work.

  • 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-05T23:37:59+00:00Added an answer on June 5, 2026 at 11:37 pm

    Based on your code I think I see what you are trying to do here. Your select statement is going to return a null on the union, so I am assuming you want to select that. I set up a test project and do the selection on the Databound event and this seems to work fine. You’ll need to go to the properties of your combobox control and set an event for DataBound. Use the following code:

        protected void PREFERENCE_DataBound(object sender, EventArgs e)
        {
            for (int i = 0; i < PREFERENCE.Items.Count; i++)
            {
                if (PREFERENCE.Items[i].GetValue("ID") == DBNull.Value)
                    PREFERENCE.Items[i].Selected = true;
            }
        }
    

    I chose ID here as the field to check for a null, but you could use name, or any other field you want.

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

Sidebar

Related Questions

How can I select a specific value in the combobox column in the datagridView
I want to select a value based on different column in SQL Server, say
In my webpage I am using combobox & searchbutton. When i select a value
Using C# & MySQL When I select the combobox value, the corresponding value should
Using C# & MySQL When i select a particular value from the combobox then
After select a value in DataGridView ComboBox and click a save button in bindingnavigator,
I want a user to select a value from a ComboBox. Entries have to
I have a combo box. When I select a value from combobox, it prints
I have a DataGrid template column with ComboBox. When I select a value and
I have a dude, i want to select a value from wpf Combobox I

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.