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
15
ItemCommand not firing. what's wrong here?
posted
This looks right to me? but when I put a breakpoint in ItemCommand, it never fires when I click the button. what's the deal? am I missing something?
The grid is manuall bount by
grid.datasource = dtData
grid.Databind()
 
<ig:WebDataGrid ID="wgDowntime" runat="server" AutoGenerateColumns="False" Height="350px" Width="1110px" OnItemCommand="wgDowntime_ItemCommand" >
        <Columns>
          
            <ig:TemplateDataField Key="DelButton" >
             <Header Text=""></Header>
                <ItemTemplate>
                    <asp:Button runat="server" ID="btnDelete" Text="Delete" CommandName="Delete1" CommandArgument='<%# Eval("MachineID").ToString()  %>' CssClass="myButton"></asp:Button>
                </ItemTemplate>
            </ig:TemplateDataField>
        </Columns>
    </ig:WebDataGrid>
    <br />
  • 3480
    Offline posted

    Hello Roger,

    I believe the same issue is discussed in this thread as well. As Jason states there, the reason the ItemCommand event is not firing 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.

    So in order to resolve this issue you need to call the EnsureTemplates() method as follows:

    if (IsPostBack) {
    
       WebDataGrid1.EnsureTemplates();
    
    }

    I implemented this approach in the attached sample application and I confirmed it worked. Please, review the sample and let us know if you need further assistance on the matter.

    5238.WDG_Template.zip