hi this is my first question on this website

I have a web form with a drop down list, which is being populated from my database which is sql-server 2012.

my table has values like genderID and genderName and it populates the drop down list but I also want to show the default value when the page load event fire "Select gender".

I can add this value in the database to be shown in drop down but this is not the perfect solution as this would mean I have entered a data in sql server which is not a valid data. how can I show this default value in the drop down list which doesnt really exist in the sql server table.

my code behind:

using(SqlConnection con = new SqlConnection(cs))
{

        using(SqlCommand cmd = new SqlCommand("select * from dbo.Gender", con))
        { 
            con.Open();
            DropDownList1.DataSource =  cmd.ExecuteReader();
            DropDownList1.DataTextField = "GenderName";
            DropDownList1.DataValueField = "ID";
            DropDownList1.DataBind();
        }
    }

When the page loads it should show "Select Gender" in the drop down list.

Related posts

Recent Viewed