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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:19:37+00:00 2026-05-28T02:19:37+00:00

When I select a value in the dropdownlist I get a postback and the

  • 0

When I select a value in the dropdownlist I get a postback and the value I selected is selected even after the postback. How do I get the default value, <–Choose City–> as selected value again after the postback?

HTML:

<asp:DropDownList ID="ddlCity" Width="200px" runat="server" AutoPostBack="true"
 OnSelectedIndexChanged="ddlCity_SelectedIndexChanged"> </asp:DropDownList>

Markup:

protected void Page_Load(object sender, EventArgs e)
{
    DataTable CityMembersTable = GetCity();
    ddlCity.DataSource = CityMembersTable;
    ddlCity.DataTextField = "CityName";
    ddlCity.DataValueField = "CityID";
    ddlCity.DataBind();

    ddlCity.Items.Insert(0, new ListItem("<--Choose City-->", ""));
}

protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ddlCity.SelectedValue == "")
    {
        return;
    }

    ddlCity.SelectedValue == "0"; //Dose not 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-05-28T02:19:38+00:00Added an answer on May 28, 2026 at 2:19 am

    You need to handle IsPostBack on page load first, because you are binding dropdown on page load. Also if your if condition executes, ddlCity.SelectedValue == "0"; will not execute.

     protected void Page_Load(object sender, EventArgs e)
     {
          if(Page.IsPostBack == false)
          {
             DataTable CityMembersTable = GetCity();
             ddlCity.DataSource = CityMembersTable;
             ddlCity.DataTextField = "CityName";
             ddlCity.DataValueField = "CityID";
             ddlCity.DataBind();
    
             ddlCity.Items.Insert(0, new ListItem("<--Choose City-->", ""));
          }
     }
    
    
     protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
     {
        ddlCity.SelectedIndex = 0; //Put this here
        if (ddlCity.SelectedValue == "")
        {
            return;
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the wrong value from my Dropdownlist (ddlCity). I always get the default
how can i get select value of dropdownlist and here is my code which
I have a dropdownlist with following options: <asp:DropDownList ID=ddlTaxStatus runat=server OnPreRender=ddlContainerStatus_PreRender> <asp:ListItem Text=--Select-- Value=-1></asp:ListItem>
I create a dropdown list by using ASP.NET MVC helper like this, <%=Html.DropDownList(Group,-please select
The premise: Get a dropdownlist's content based on the value selected in the first
I am struggling to get the selected value from the hard-coded dropdownlist in mvc
How can I get the value from a select field (dropdownlist) into a code
I want to select Algeria as default selected value in drop down list.I am
I am having trouble getting the selected value in an asp:DropDownList. I am using
this is my drpdownlist <asp:DropDownList ID=DriverGender runat=server> <asp:ListItem Text=M Value=M></asp:ListItem> <asp:ListItem Text=F Value=F></asp:ListItem> </asp:DropDownList>

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.