I put Dropdownlist inside my GridView1, and the dropdownlist has values 0 and 1. What I want is: depending on the selected value from dropDownlist to update the column [Status] whit that value in my sql database???
protected void SQL_Update(object sender, GridViewUpdateEventArgs e){
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=Korisnik;Integrated Security=True";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "UPDATE RegistracijaKorisnik SET Status = " + ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList2")).SelectedValue; ;
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();}
Let’s say you have the DropDownList and you bind it whichever way:
In your code behind, you should have an Updating event, specifically using
GridViewUpdateEventArgs e