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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:32:14+00:00 2026-06-04T10:32:14+00:00

The above error occurs on a SelectedIndexChanged click event on a listbox. in debug

  • 0

The above error occurs on a SelectedIndexChanged click event on a listbox.

in debug the value returned is “”, however when you look at the webpage source code there are definitely values.

Here’s my listbox:

<asp:ListBox ID="lstBxMyList" runat="server" CssClass="binorderlst1"
     DataTextField="myName" 
     DataValueField="myID" 
     OnSelectedIndexChanged ="lstBxMyList_SelectedIndexChanged"
     AutoPostBack="true" Rows="10">
</asp:ListBox>

Here’s the event:

protected void lstBxMyList_SelectedIndexChanged(object sender, EventArgs e)
{
    myID = Convert.ToInt32(lstBxSiteList.SelectedValue.ToString());

    ... rest of code
}

For completeness here’s the data binding:

private void BindLstBxMyList(int myOtherID)
    {
        DataTable dt = new DataTable();
        SqlConnection conn;
        SqlCommand comm;

        using (conn = new SqlConnection(aSHconns.aconn))
        {
            comm = new SqlCommand("myStoredProc", conn);
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add(new SqlParameter("@myOtherID", SqlDbType.Int));
            comm.Parameters["@myOtherID"].Value = myOtherID;
            SqlDataAdapter sqlDa = new SqlDataAdapter(comm);

            try
            {
                conn.Open();
                 sqlDa.Fill(dt);
                 if (dt.Rows.Count > 0)
                 {
                     lstBxMyList.DataSource = dt;
                     lstBxMyList.DataTextField = "myName";
                     lstBxMyList.DataValueField = "myID";
                     lstBxMyList.DataBind();
                 }

            }

            finally 
            {
                conn.Close();
            }
        }

    }

If I revert back to a SqlDataSource the listbox returns values. Bt I need to repopulate the list, so I need the code behind databind (unless there is a better way of course)

So why is the listbox selected value returning an empty string? Any help would be gratefully received.

  • 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-04T10:32:16+00:00Added an answer on June 4, 2026 at 10:32 am

    You have property AutoPostBack = “True” this will make a postback on each selected index changed. So, before it goes to Selected index changed event it has to hit Page load where you are binding your listbox. So, when it hits page load, the selected index will be changed to default item. So, try the following code.

     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                 //Bind your listbox here
                }
             }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting the above error in following code. How to rectify it. Thanks. Please look
Anyone got any ideas? The above error occurs when the following code is run:
The above error message appears when I am trying to get Column Value from
My code gives the above error. I have tried to change it based on
I have no code behind and the above error keep prompting on INSERT. The
Above error message occurs with this statement: SELECT f.fullname INTO SummaryJudgment_FinalForgottenWithMiddle FROM ( (SELECT
From the above image you can see that an error occurs when the function
Can please some tell me when does the above written error occurs. I just
I am getting the above error in my VS 2008 C# method when I
I get the above error message (which I googled and found is something to

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.