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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:21:39+00:00 2026-06-02T12:21:39+00:00

I have a ListBox in my webpage that is bound from database in this

  • 0

I have a ListBox in my webpage that is bound from database in this way:

    ListBox1.DataTextField = "Text";
    ListBox1.DataValueField = "MenuID";
    ListBox1.DataSource = SqlHelper.ExecuteReader(DAL.DALBase.ConnectionString, "GetMenu");
    ListBox1.DataBind();

I want to get selected item value and used this code but have a error and does not worked.

ListBox1.SelectedValue;

Forgive me if I have problems on how to write because my English is not good.

  • 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-02T12:21:40+00:00Added an answer on June 2, 2026 at 12:21 pm

    Can you be more specific on the error you are getting?

    Using ListBox1.SelectedValue should work.

    For example:

    int mySelectedValue = int.Parse(ListBox1.SelectedValue);
    

    or

    string mySelectedValue = ListBox1.SelectedValue;
    

    Edit

    Added code to ensure the original poster was keeping values in ListBox databound.

    protected void Page_Load( object sender, EventArgs e)
    {
       if (!Page.IsPostBack)
       {
           BindListBox();
       }
    }
    
    private BindListBox()
    {
       ListBox1.DataTextField = "Text";
       ListBox1.DataValueField = "MenuID";
       ListBox1.DataSource = SqlHelper.ExecuteReader(DAL.DALBase.ConnectionString, "GetMenu");
       ListBox1.DataBind();
    }
    
    protected void SomeButton_Click( object sender, EventArgs e)
    {
       string mySelectedValue = ListBox1.SelectedValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a listbox that is populated this way with two Databindings (Frage and
I have a listbox that users can add/remove from. To add, there's a text
I have a ListBox that has a style defined for ListBoxItems. Inside this style,
I have this ListBox which is bound to an ObservableCollection. Each object in the
I have ListBox and want to put values in this listbox from a DataTable
I have a simple webpage that adds & deletes options from a select element
I have a listbox bound to an Dictionary that holds my ViewModels, the listbox
I have a listbox that is databound to a Collection of objects. The listbox
I have a ListBox that when in focus, and when I have an item
I have WPF ListBox which is bound to a ObservableCollection, when the collection changes,

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.