Last post Mar 30, 2018 04:08 PM by Torby
Mar 29, 2018 09:00 PM|Torby|LINK
Have dropdown list on web form:
<asp:DropDownList ID="ddService" runat="server" OnSelectedIndexChanged="ddService_SelectedIndexChanged"></asp:DropDownList>
List is filled by code on page load if it's not a postback:
ddService.Items.Add( new ListItem(rd["CategoryName"].ToString(), rd["CategoryPK"].ToString()));
Clearly, the data comes from a database.
When you select one of the items in the list, I want to refresh the list, but my event handler isn't getting called:
protected void ddService_SelectedIndexChanged(object sender, EventArgs e)
I put a breakpoint inside the event handler, but it never hits.
And I don't see why. Do any of you?
Mar 30, 2018 02:02 AM|markfitzme|LINK
Try setting autopostback="true" on the control.
Mar 30, 2018 03:16 AM|Eric Du|LINK
According to your description and code, as far as i know, the solution is as markfitzme said, you need add autopostback="true" to the control. About how and why to use it, you
could check this tutorial:
How to use DropDownList AutoPostBack in asp.net c#:
Mar 30, 2018 04:08 PM|Torby|LINK
Bingo! I knew it would be something obvious to the less oblivious.
Indeed, last time I used a drop list, I had autopostback=true.
Now I do this time.