Reputation: 2851
I have a dropdown list which is populated on page_load using a linq query. If I change the value in the dropdown then click a button to run an update query on the record, the original value is still there, if I step through in debug mode I can see the selected value is not changing at all
Here is how Im binding the data to dropdown
dlBookingRef.DataSource = d.BookingRef();
dlBookingRef.DataMember = "booking";
dlBookingRef.DataBind();
and here is the line in the function which gets the data from the form
item.booking_ref = dlBookingRef.SelectedValue;
Any idea why it's retaining its original value?
thanks
Upvotes: 0
Views: 33
Reputation: 62488
Put the binding code in if(!IsPostBack)
, it looks like that in button event as page load gets called due to that your dropdown list gets reset, so bind the dropdown only when page is not posted back:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
dlBookingRef.DataSource = d.BookingRef();
dlBookingRef.DataMember = "booking";
dlBookingRef.DataBind();
}
}
Upvotes: 1