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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:14:55+00:00 2026-05-21T02:14:55+00:00

This is my first web page ever and I can’t seem to find the

  • 0

This is my first web page ever and I can’t seem to find the correct way to get the selected index from a dropdown list. I don’t need the selected index until the user presses the submit button. I’ve been testing everything I’ve found on the subject, but nothing is working.

I don’t want the drop-down box to reset when the selection is made, which is what happens if I use postback=true or any selected index changed events. And, I still get an index of 0.

When I test, the selected index is always zero.

This runs on page load:

 ddlBudgetLineItem.DataSource = budget.BudgetLineItems;
 ddlBudgetLineItem.DataTextField = "Name";
 ddlBudgetLineItem.DataValueField = "BudgetLineItemID";
 ddlBudgetLineItem.DataBind();

This is the drop-down list:

<asp:DropDownList ID="ddlBudgetLineItem" runat="server">
            </asp:DropDownList>

Here is the code that needs the index:

protected void submitPayment()
    {            
        string amountValue = txtAmount.Text.ToString();

        float amount = float.Parse(amountValue);

        Payment payment = new Payment()
        {
            Amount = amount,
            Payee = txtPayee.Text,
            BudgetLineItem = budget.BudgetLineItems[ddlBudgetLineItem.SelectedIndex],
            Memo = txtMemo.Text,
            PaymentDate = DateTime.Parse(txtPaymentDate.Text),
            ExtraUserInfo = info
        };

        provider.AddPayment(payment);
    }

Any assistance is appreciated.

  • 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-05-21T02:14:56+00:00Added an answer on May 21, 2026 at 2:14 am

    it seems to be a life cycle issue, this is happening because everytime (on a postback or not) the page is loaded, your dropdown is rebuilt (caused by ddlBudgetLineItem.DataBind()), concluding that on a postback your ddl will get index=0 forever.

    how can you solve this:

    1: Override the page databind method and put your code before call base.databind(); (inside the method)

    2: on your load event you just have to call databind (if not is postback), it prevent to rebuild your object states everytime your page is loaded.(cause of your lost information).

    3: take a look on a page lifecycle it will help you to prevent future issues like that.

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

Sidebar

Related Questions

Code first: '''this is main structure of my program''' from twisted.web import http from
I'm attempting to get my first ASP.NET web page working on windows using Mono
This is my first time doing VB :-) I've inherited a web site, which
first of all this is my third question about web services here and i
Here's the scenario: if this is a user's first time logging into my web
First of all, I am a WEB NOOB. Which probably explains this question. Anyway,
this is my first time ever posting a question and I am kind of
I'm working on my first ever ASP.Net project, and I seem to have been
As per my knowledge when ever a web-page is loading, always header is loading
so here goes my first real coding question ever on the web since normally

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.