When I use the code below an error accur when click add button to insert into sql because the selected value in DropDownList is back to --select-- Idon't know why it should be the the value I selected
but when not use this code and bind the DropDownList
using wizard it works but I need to use the code to make the first selection is --select--.
private void PopulateDropDownList()
{
string constr = ConfigurationManager.ConnectionStrings[1].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Country_ID,Country_Name FROM Country", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
this.ddl_countryOfcomp_add.DataTextField = "Country_Name";
this.ddl_countryOfcomp_add.DataValueField = "Country_ID";
this.ddl_countryOfcomp_add.DataSource = ds; this.ddl_countryOfcomp_add.DataBind();
this.ddl_countryOfcomp_add.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--Select--", "0"));