problem with dropdownlist
-
In the project I am working on ,I need to add new records in a database and show the first column of all these existing records in a dropdownlist on the same page.The problem is that when I add a new record its value doesn't get reflected in the dropdownlist and I need to refresh the page to see the changes.What should I do so that I will not need to refresh the page and still the value will get added to dropdownlist. Thank you.
-
In the project I am working on ,I need to add new records in a database and show the first column of all these existing records in a dropdownlist on the same page.The problem is that when I add a new record its value doesn't get reflected in the dropdownlist and I need to refresh the page to see the changes.What should I do so that I will not need to refresh the page and still the value will get added to dropdownlist. Thank you.
-
I have already done it ,my code on page load is query = "select * from CashDataTable"; conn = new OleDbConnection("FILE NAME=C:\\abc.udl"); conn.Open(); cmd = new OleDbCommand(query,conn); reader = cmd.ExecuteReader(); DropDownList1.DataSource = reader; DropDownList1.DataTextField = "AcctNumber"; DropDownList1.DataValueField = "AcctNumber"; DropDownList1.DataBind(); conn.Close(); but still it doesn't work.
-
I have already done it ,my code on page load is query = "select * from CashDataTable"; conn = new OleDbConnection("FILE NAME=C:\\abc.udl"); conn.Open(); cmd = new OleDbCommand(query,conn); reader = cmd.ExecuteReader(); DropDownList1.DataSource = reader; DropDownList1.DataTextField = "AcctNumber"; DropDownList1.DataValueField = "AcctNumber"; DropDownList1.DataBind(); conn.Close(); but still it doesn't work.
you are doing that on Page_Load, that only runs when the page loads, that's why it updates when you refresh the page, if you want to force it to update you need to call DataBind again. I don't know how you are updating the database, You might need to set the autopostback of controls that update the database to true. In that case you won't need a separate call to the DataBind method because it's executed at the database level, however, it also depends on what you are doing the the dropdownlist, if you want to keep the selection the user makes you need to check the IsPostBack property and not bind the control every time the page loads,again, not knowing more is difficult to say how to do it.