OnDataBound not fired for asp:DropDownList with st

2019-07-31 23:43发布

I have an <asp:DropDownList> witch gets filled by static list items.

<asp:DropDownList ... OnDataBound="handlerMethod">
    <asp:ListItem Value="..." Text="..." />
    <asp:ListItem Value="..." Text="..." />
    <asp:ListItem Value="..." Text="..." />
</asp:DropDownList>

The problem is that the OnDataBound event does not get triggered when the list is filled. I need it to trigger to fill some other data from the list items that are in the dropdown.

The documentation says:

This method notifies a server control that any data binding logic associated with the control has completed.

My eyes are on this "logic" word which makes me thing that i missed the point on when the event is triggered

But if that is the case, how can I get the event triggered or what other event can I use to know when the list has finished beeing filled?

1条回答
霸刀☆藐视天下
2楼-- · 2019-08-01 00:17

Normally this means that you have deleted the AutoEventWireup="true" or set it to false, and that's why it's not wiring up the event.

It can also mean that there is something wrong in the javascript that does not allow anymore code to run. Open the inspector (Chrome, Safari or Firebug in Firefox - Do not rely on IE Developer tools) and see if you have any javascript errors that can cause the page to stop.

It can also mean that the handlerMethod is not correctly set up, best way is to delete the html part OnDataBound="handlerMethod" and the code behind of this method, then go to design view, open the Properties window in the Events and double click the OnDataBound, it will add the event correctly. Set up a break point there and run in debug with debug="true" in your web.config file.

查看更多
登录 后发表回答