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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:40:27+00:00 2026-05-17T00:40:27+00:00

I am populating a DropDownList control as follows – public partial class UserControls_PMS_Send2DeliveryTeam :

  • 0

I am populating a DropDownList control as follows –

public partial class UserControls_PMS_Send2DeliveryTeam : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            // SA 100928 Get the delivery teams and their respective email addresses
            string[] delTeam = ConfigurationManager
                               .AppSettings["deliveryTeamNames"]
                               .Split(',');
            string[] delTeamEmails = ConfigurationManager
                                     .AppSettings["deliveryTeamEmails"]
                                     .Split('|');

            if (delTeam.Length != delTeamEmails.Length)
            {
                showAlert("You have an error in the configuration of the delivery teams");
                return;
            }

            for(int looper=0; looper<delTeam.Length; looper++)
                delTeamDDList
                .Items
                .Add
                ( 
                    new ListItem(delTeam[looper], delTeamEmails[looper])
                );

        }

    // Other methods
}

But whenever user selects a value from this dropdown, only the first item is being selected. To clarify more, suppose that the list has 4 items, item 1, item 2, item 3 and item 4. When user selects 4th item from the lists, it selects item 1 as the selected value.

What’s the reason behind this?

EDIT

I have just checked the generated HTML for the DropDownList using firebug, and it seems the “selected” value doesn’t change at all even if I choose different values from the DropDownList.

The generated HTML is as follows –

<select class="select" id="Send2DeliveryTeam_delTeamDDList" name="Send2DeliveryTeam$delTeamDDList">
    <option value="value1" selected="selected">Project Initiation Team</option>
    <option value="value2">Service Delivery Centre</option>
    <option value="value3">TCS</option>
    <option value="value4">PIT &amp; SDC</option>
    <option value="value5">SDC &amp; TCS</option>
    <option value="value6">PIT &amp; TCS</option>
    <option value="value7">PIT &amp; SDC &amp; TCS</option>
</select>

First, user selects a value from this dropdown list. Then he presses a button, which fires the click event. The button’s corresponding event-handler function is the place where I am accessing the dropdownlist’s selected value. The code is as follows –

// Button event-handler code
protected void assignDelTeamButton_Click(object sender, EventArgs e)
{
    // This is where I am always getting the same value, no matther what I choose
    // from the dropdown list, and this value is the one which is selected by default
    // when the page loads. I mean, the "SelectedIndex" is always 0.
    string selected_value = delTeamDDList.SelectedItem.ToString();

    // Other  codes
}

The ascx file –

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Send2DeliveryTeam.ascx.cs" Inherits="UserControls_PMS_Send2DeliveryTeam" %>
<div id="Common">
    <h3>Welcome <%string user = HttpContext.Current.Session["user_name"].ToString();%><%=user %></h3>
    <h1>Request Estimate Screen</h1>
    <span>Request Estimate and Assign a Delivery team to a Request</span><br />
    <label>Enter an existing project number</label>
    <asp:TextBox ID="reqNum" runat="server" CssClass="textBox" /><br />
    <label>Select Delivery Team</label>
    <asp:DropDownList ID="delTeamDDList" runat="server" CssClass="select" >

    </asp:DropDownList>
    <label> - Sorted in alpha order</label><br /><br />
    <label>&nbsp;</label>
    <asp:button ID="assignDelTeamButton" runat="server" Text="Continue" 
    CssClass="button" onclick="assignDelTeamButton_Click"/><br />
</div>

Second Edit

If I hard-code the ListItems as follows, it works perfectly –

<asp:DropDownList ID="delTeamDDList" runat="server" CssClass="select" >
    <asp:ListItem Text="Project Initiation Team" Value="email1@yahoo.com"></asp:ListItem> 
    <asp:ListItem Text="Service Delivery Centre" Value="email2@yahoo.com"></asp:ListItem>
    <asp:ListItem Text="TCS" Value="email3@yahoo.com"></asp:ListItem> 
    <asp:ListItem Text="PIT & SDC" Value="email4@yahoo.com"></asp:ListItem> 
    <asp:ListItem Text="SDC & TCS" Value="email5@yahoo.com"></asp:ListItem> 
    <asp:ListItem Text="PIT & TCS" Value="email6@yahoo.com"></asp:ListItem> 
    <asp:ListItem Text="PIT & SDC & TCS" Value="email7@yahoo.com"></asp:ListItem> 
</asp:DropDownList>
  • 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-17T00:40:28+00:00Added an answer on May 17, 2026 at 12:40 am

    Do one of the following:

    1. Turn on ViewState in Web.config or containing page if it’s off there.
    2. Better yet, make sure ViewState is still enabled, but populate your DDL in your User Control’s Init (but don’t wrap it with !IsPostBack). This will have your data access logic on every page/control init, even on postback, but it won’t add unnecessary data to ViewState as you’re not init’ing your DLL, then having ViewState track the changes you make to it’s data source. However, you still want ViewState because DDLs in ASP.NET require ViewState in order to track the selected index/value on postback (if you completely turn off ViewState you can only get the DDLs posted back selected value by finding it in the posted Request’s FORM NameValueCollection).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp.net 2.0 web site with numerous asp:DropDownList controls. The DropDownList control
Does anyone have an example of using of populating a YUI DataTable with a
I am cloning a hidden table row then populating it and after validation I
I am using GridView in my application for populating datas. Is there any easy
I have a Drupal module page where I am populating a form with a
I would like to know what the best practice for populating a business object
I'm doing some Objective-C programming that involves parsing an NSXmlDocument and populating an objects
I am currently building a .Net userform using C# and I am populating it
I did follow the article TRULLY Understanding ViewState (great article btw) and populating my
Initialization would include creating all the required tables, constraints and populating the tables. edit:

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.