Обновить источник данных dropdownlist в ASP.NET
Hi I am new in c# for first assignment. I had successfully load data from dropdownlist into my textfield. Also manage to insert, update and delete the records from database table. Now, I am facing this problem. Each new record insert into db table, update or delete, my dropdownlist which load from Page_Load doesn't not refresh my dropdownlist. I do some research online, instead of using ajax. I may use another trick code which is DropDownList2.DataBind(); Anyhow,it still doesn't work to refresh my Dropdown list. Any expert can give me some advise. Did I place the line of code wrongly? Below is my code for delete function.
Что я уже пробовал:
connection.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ToString(); connection.Open(); NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = connection; cmd.CommandText = "Delete from student_db where id=@id"; cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new NpgsqlParameter("@id", Convert.ToInt32(DropDownList2.SelectedItem.Value))); cmd.ExecuteNonQuery(); cmd.Dispose(); DropDownList2.DataBind(); connection.Close();