I have a dropdownlist thats generaqted from a dataset.
By default the first value is selected of course.
When I submit the form it keeps on sending through the first value (currently selected one) even though I have selected a different one.
See below the code for the dataset generator and the on_Click function.
The On_Click function
protected void AddNewArea_Click(object sender, EventArgs e)
{
string connString = "Data Source=.\\SQLExpress;Integrated Security=true; AttachDbFilename=|DataDirectory|\\Database.mdf;User Instance=true;";
SqlConnection conn = new SqlConnection(connString);
// INSERT Query
string cmdString = "INSERT INTO LodgeAreas " +
"( AreaName, pid) " +
"VALUES('" + areaname.Text + "','" + area.SelectedItem.Value + "')";
SqlCommand cmd = new SqlCommand(cmdString, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
//errmsg2.Text = cmdString;
}
The Dropdown List:
public void getDropDown2()
{
SqlConnection conn = new SqlConnection("Data Source=.\\SQLExpress;Integrated Security=true; AttachDbFilename=|DataDirectory|\\Database.mdf;User Instance=true;");
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM content WHERE pid = '3'", conn);
DataSet ds = new DataSet();
da.Fill(ds);
area.DataTextField = "pageTitle"; //Set the column name which is shown as dropdown text
area.DataValueField = "id"; //this is for value
area.DataSource = ds; //set the datasource here
area.DataBind(); //bind the dataset
}
tx

New Topic/Question
Reply




MultiQuote






|