How to add additional value in DropDownList if populate from SQL D

Giganews Newsgroups
Subject: How to add additional value in DropDownList if populate from SQL D
Posted by:  will~ (wi…@discussions.microsoft.com)
Date: Fri, 7 Mar 2008

VS 2005[c#], SQL Server 2005, Windows XP Pro SP2

I have created a webpage that contains a GridView control, multiple
DropDownList control and a button.  The DropDownLists are populated from
various tables in an SQL database.  Please could you advice me on the
following?

* How could I add two option on each of the DropDownLists?  I would like to
add "Please Select" and "All Types" for all DropDownLists, and the user would
see "Please Select" as default.  (The list was populated from a SQL table -
See coding extract below)  Could I do this in the coding (code-behind)?  Many
thanks in advance,

            #region This bit populates the dropdown list products
            command = new SqlCommand("SELECT ProductID, ProductName FROM
TableA", conn);
            command.CommandType = CommandType.Text;

            try
            {
                conn.Open();

                SqlDataAdapter adapter = new SqlDataAdapter(command);

                DataSet dataset = new DataSet();
                DataTable myTable = new DataTable("Product");
                adapter.Fill(myTable);

                dataset.Tables.Add(myTable);

                DropDownListCourseType.DataSource = dataset.Tables["Product"];
                DropDownListCourseType.DataTextField = "ProductName";
                DropDownListCourseType.DataValueField = "ProductID";
                DropDownListCourseType.DataBind();
            }
            catch
            {
                //this executes if an error occurs
            }
            finally
            {
                conn.Close();
            }
            #endregion

Replies