Reputation: 2660
I'm currently working on an old asp website but im running into some problems. I have to say that im not very up to speed with asp.net. I have a DropDownList with items (days - Monday / Friday) that i have hard coded.
I'm trying to change the index based on the date that gets selected by a calender control that inserts the date in text form into a text-field. On the text-changed event of the text-field I'm trying to change the index.
When I put a quick watch on the selected index I see that index change correctly based on the date but for some reason the actual control is not updated on the website.
I already enabled autoPostBack but that did not help unfortunately.
textChanged code:
tbLoadFrom.Text = Util.ToTime(_programSession.GetTime(customer, address, customer.DefaultLoadTimeFrom, "LoadFrom", Util.ToIntBasedDayOfWeek(Convert.ToDateTime(tbLoadDate.Text).DayOfWeek)));
tbLoadTill.Text = Util.ToTime(_programSession.GetTime(customer, address, customer.DefaultLoadTimeTill, "LoadTill", Util.ToIntBasedDayOfWeek(Convert.ToDateTime(tbLoadDate.Text).DayOfWeek)));
ddl_LoadTimeDay.SelectedIndex = Util.ToIntBasedDayOfWeek(Convert.ToDateTime(tbLoadDate.Text).DayOfWeek);
ddl_LoadTimeDay.DataBind();
DropDownList:
<asp:DropDownList ID="ddl_LoadTimeDay" runat="server" EnableViewState="true" AutoPostBack="True" OnSelectedIndexChanged="ddl_LoadTimeDay_SelectedIndexChanged">
<asp:ListItem Value="0">Maandag</asp:ListItem>
<asp:ListItem Value="1">Dinsdag</asp:ListItem>
<asp:ListItem Value="2">Woensdag</asp:ListItem>
<asp:ListItem Value="3">Donderdag</asp:ListItem>
<asp:ListItem Value="4">Vrijdag</asp:ListItem>
<asp:ListItem Value="5">Default</asp:ListItem>
</asp:DropDownList>
Upvotes: 0
Views: 972
Reputation: 2660
The date text-field was in a separate update-panel. I removed this panel and called the parent update-panel to update. This works like a charm.
Upvotes: 0
Reputation: 3297
In text changed event remove DataBind() ofr the Dropdownlist
tbLoadFrom.Text = Util.ToTime(_programSession.GetTime(customer, address, customer.DefaultLoadTimeFrom, "LoadFrom", Util.ToIntBasedDayOfWeek(Convert.ToDateTime(tbLoadDate.Text).DayOfWeek)));
tbLoadTill.Text = Util.ToTime(_programSession.GetTime(customer, address, customer.DefaultLoadTimeTill, "LoadTill", Util.ToIntBasedDayOfWeek(Convert.ToDateTime(tbLoadDate.Text).DayOfWeek)));
ddl_LoadTimeDay.SelectedIndex = Util.ToIntBasedDayOfWeek(Convert.ToDateTime(tbLoadDate.Text).DayOfWeek);
ddl_LoadTimeDay.DataBind(); //Remove this
This line will make ASP.NET to load the data again from the datasource and your selected Index will be clear and set to default.
Upvotes: 1