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

  • Home
  • SEARCH
  • 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 6324751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:45:48+00:00 2026-05-24T16:45:48+00:00

I placed a dropdown list in my asp page <asp:DropDownList ID=authorList runat=server OnSelectedIndexChanged=authorList_Changed AutoPostBack=true

  • 0

I placed a dropdown list in my asp page

 <asp:DropDownList ID="authorList" runat="server"     
  OnSelectedIndexChanged="authorList_Changed" AutoPostBack="true"
   ></asp:DropDownList>

Then in codebehind, I bind it to a filed in database and then fire selectedindexchanged

  protected void Page_Load(object sender, EventArgs e)
    {

        var a = (from s in p.Authors
                 select s.FirstName);
        authorList.DataSource = p.Authors;
        authorList.DataTextField = "Firstname";
        authorList.DataValueField = "FirstName";
        authorList.DataBind();
        authorList.SelectedIndexChanged += new EventHandler(authorList_Changed); 
        var q = (from s in p.Authors
                 where s.FirstName.Contains("m") 
                 select s);
        Grid1.DataSource = q;
        Grid1.DataBind();
       // authorList.DisplayMember = "FirstName";
    }
    public void authorList_Changed(Object sender, EventArgs e)
    {
        //Author a = (Author) authorList.SelectedItem;   
        var a = authorList.SelectedValue;
        var v = authorList.SelectedItem;
        var q2 = (from s in p.Authors
                  from w in p.Payrolls
                  where authorList.SelectedValue == s.FirstName
                  where s.AuthorID == w.AuthorID
                  select w);
        List<Payroll> d = q2.ToList();
        if (d.Count > 0)
        {
            payroltextbox.Text = d.First().PayrollID.ToString();
            //authorList.DataBind();
        }
        else
            payroltextbox.Text = "";
           // authorList.DataBind();

    }
    PublishingCompanyEntities p = new PublishingCompanyEntities();

But the problem has been that when my dropdown has values say 1 2 3 4 ……. 1 bring default……. So, when I select 4 it still returns 1 on postback and return the value in textbox(payroltextbox) associated with 1.. Can u please help me…..

  • 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-24T16:45:49+00:00Added an answer on May 24, 2026 at 4:45 pm

    It’s because you’re forgetting to check for Page.IsPostback in Page_Load…

    Page_Load happens each time the page is loaded, even if it’s on postback, so the firstdrop-down is being repopulated BEFORE the authorList_Changed event. This is causing the firtst item to be re-selected.

    Refer to the Page Lifecycle.

    and put your databinding code in the Page_Load inside an if statement like so:

      protected void Page_Load(object sender, EventArgs e)
        {
           if(!Page.IsPostback)
           {
              var a = (from s in p.Authors
                       select s.FirstName);
              authorList.DataSource = p.Authors;
              authorList.DataTextField = "Firstname";
              authorList.DataValueField = "FirstName";
              authorList.DataBind();
              authorList.SelectedIndexChanged += new EventHandler(authorList_Changed); 
              var q = (from s in p.Authors
                       where s.FirstName.Contains("m") 
                       select s);
              Grid1.DataSource = q;
              Grid1.DataBind();
             // authorList.DisplayMember = "FirstName";
           }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my aspx <asp:Content ID=Content2 ContentPlaceHolderID=ContentPlaceHolder1 runat=server> <asp:ObjectDataSource ID=DSCategories runat=server SelectMethod=GetCategories TypeName=BAL.CategoryBAL> </asp:ObjectDataSource>
Good day. I have a dropdown list control called audioList. Whenever the page loads
I have a DataGrid that looks like this (slightly simplified here): <asp:DataGrid ID=grdQuotas runat=server
I have a DataPager control that looks like this: <asp:DataPager ID=page1 PagedControlID=ExperienceList runat=server PageSize=3
in ASP.Net datagrid I placed one dropdown and a textbox (multiline). I needs to
I made a windows form with many dropdown list which are placed inside a
I have a Template Column under which I have Placed a Dropdownlist. Now I
I have placed an image on the master page. I see the image at
I have an asp.net page with some JQuery tabs. Everything works ok. I added
What is the best way to do a city/country dropdown pair in ASP.NET MVC?

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.