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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:12:47+00:00 2026-05-24T19:12:47+00:00

I have a DropDownList, when the form is first opened it selects the first

  • 0

I have a DropDownList, when the form is first opened it selects the first entry found in the database. What I want it to do is display “Select.” But I don’t want the “Select” message to hold any value towards my database (I don’t want the system to think this is an option to edit into the database).

What I’m trying at the moment is:

<asp:DropDownList ID="DropDownListEmployee" runat="server"  
                  AutoPostBack="True" 
                  OnSelectedIndexChanged="SelectionHasChanged"
                  DataSourceID="SqlDataSource1" DataTextField="Fullname"  
                  DataValueField="Employee_ID" Width="214px">
    <asp:ListItem>Select</asp:ListItem>

I have tried using:

dropdownList.DataBind();
dropdownList.Items.Insert(0, new ListItem("Select")); 

This solution kept setting “Select” into txt/data fields in which it did not belong, causing issues when trying to update, insert, or delete from database.

Also, how do I edit my posts so that it shows the code?

================ Code Behind File ================

namespace MyProject.Update
{
    public partial class UpdateEmployee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void SelectionHasChanged(Object sender, System.EventArgs e)
        {

            string connectionString = WebConfigurationManager.ConnectionStrings["DBConnectionString1"].ConnectionString;


            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("Retreive", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 7));
            cmd.Parameters["@ID"].Value = Convert.ToInt32(DropDownListEmployee.SelectedValue.ToString());


            try
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    txt1.Text = (string)reader["1"];
                    txt2.Text = (string)reader["2"];
                    txt3.Text = (string)reader["3"];
                    txt4.Text = (string)reader["4"];
                    txt5.Text = (string)reader["5"];
                    txt6.Text = (string)reader["6"];
                    txt7.Text = (string)reader["7"];
                    txt8.Text = DropDownListEmployee.SelectedValue.ToString();
                }

                reader.Close();

            }

            catch (SqlException err)
            {
                // Replace the error with something less specific.
                // You could also log the error now.
                throw new ApplicationException("Data error.");
            }
            finally
            {
                con.Close();
            }
        }


        protected void UpdateEmployeeBTN_Click(object sender, EventArgs e)
        {
            string connectionString = WebConfigurationManager.ConnectionStrings["DBConnectionString1"].ConnectionString;


            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("Change", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 7));
            cmd.Parameters["@ID"].Value = Convert.ToInt32(DropDownListEmployee.SelectedValue.ToString());



            cmd.Parameters.Add(new SqlParameter("@1", SqlDbType.VarChar, 20));
            cmd.Parameters["@1"].Value = txt1.Text;

            cmd.Parameters.Add(new SqlParameter("@2", SqlDbType.VarChar, 20));
            cmd.Parameters["@2"].Value = txt2.Text;

            cmd.Parameters.Add(new SqlParameter("@3", SqlDbType.VarChar, 100));
            cmd.Parameters["@3"].Value = txt3_Address.Text;

            cmd.Parameters.Add(new SqlParameter("@4", SqlDbType.VarChar, 100));
            cmd.Parameters["@4"].Value = txt4.Text;

            cmd.Parameters.Add(new SqlParameter("@5", SqlDbType.Char, 12));
            cmd.Parameters["@5"].Value = txt5.Text;

            cmd.Parameters.Add(new SqlParameter("@6", SqlDbType.Char, 12));
            cmd.Parameters["@6"].Value = txt6.Text;

            cmd.Parameters.Add(new SqlParameter("@7", SqlDbType.VarChar, 50));
            cmd.Parameters["@7"].Value = txt7.Text;


            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                txtID.Text = Convert.ToString(cmd.Parameters["@ID"].Value);
            }
            catch (SqlException err)
            {
                // Replace the error with something less specific.
                // You could also log the error now.
                throw new ApplicationException("Data error.");
            }
            finally
            {
                con.Close();
            }

        }
  • 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-24T19:12:50+00:00Added an answer on May 24, 2026 at 7:12 pm

    Try using the AppendDataBoundItems attribute:

    <asp:DropDownList ID="DropDownListEmployee" runat="server"  
                      AutoPostBack="True" 
                      OnSelectedIndexChanged="SelectionHasChanged"
                      DataSourceID="SqlDataSource1" DataTextField="Fullname"  
                      DataValueField="Employee_ID" Width="214px"
                      AppendDataBoundItems="true">
        <asp:ListItem Value="" Text="Select" />
    

    This will allow you to add the databound items to the list without affecting anything you declared prior. Just make sure you add any items to the list before you call DataBind().

    ListControl.AppendDataBoundItems Property

    ADDED

    Based on the code behind you pasted, I believe both ShankarSangoli and rudeovski ze bear have viable approaches for you. You need to check to ensure the user has made a selection in the DropDownList, and either throw an error if they didn’t or provide some default value.

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

Sidebar

Related Questions

I have this MVC form with 2 dropdownlist where selection on the first dropdown
I have a dropdownlist and a textbox with a button on a form. When
I have got 2 DropDownList s on my Form and 1 GridView . I
I have a windows form with a DropDownList with a fixed number of items.
I have DropDownList with CascadingDropDown extender. If I want to retrieve data from the
I have a dropdownlist with the autopostback set to true. I want the user
I have two select lists, and I want the selection for both to go
I want to first form a 3-digit code once a user enters some input
I have a simple ASP.NET form with a DropDownList and two RadioButtons (that both
I have 2 multi-select Html.DropDownList controls with a button between them. When the user

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.