Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
620
Web Data Grid ItemCommand Not Firing
posted

Since the version 14.1.20141.2283 upgrade, clicking a link button inside a Template Item does not fire the ItemCommand  method when a webdatagrid is set to EnableDataViewState="true". If I set EnableDataViewState="false" and rebind the grid each postback the ItemCommand method fires as expected. This behavior was not occurring in the previous version of 14.1. Is this a known error? How can I fix it with rebinding my grids on each postback?

Parents
No Data
Reply
  • 8421
    Verified Answer
    posted

    Hello droedger,

    The reason that the ItemCommand event is failing to fire is that templates of the grid are instantiated in the DataBind method of the grid. Normally if this method is not manually called it gets called during the OnPreRender event for the grid. However, when using this with the ItemCommand the DataBind event is fired after the ItemCommand event is supposed to fire. Since the templates haven't been instantiated in time the event can't find the templates and fails out silently.

    The way to resolve this issue is to ensure that the templates exist. You can do this by adding the following code to your PageLoad event:

    if (IsPostBack) {

       WebDataGrid1.EnsureTemplates();
    }

    The way that it was working previously in the older versions was not actually the intended behavior of the control. This new approach is the correct way to implement ItemCommands, TemplateColumns, and EnableDataViewState. Please let me know if you have any questions or concerns about this approach, or let me know if I may be of any other help.

Children