OnDataBound not fired for asp:DropDownList with static asp:ListItems

被刻印的时光 ゝ 提交于 2019-12-24 08:35:15

问题


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:


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.



来源:https://stackoverflow.com/questions/6621510/ondatabound-not-fired-for-aspdropdownlist-with-static-asplistitems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!