ItemCommand event not firing

13 posts, 1 answers
  1. Juri Strumpflohner
    Juri Strumpflohner avatar
    2 posts
    Member since:
    Oct 2009

    Posted 12 Oct 2009 Link to this post

    Hi,
    I'm quite new to RAD controls, so be patient :)
    I just started to experiment a bit with the RadGrid. I used the client-side binding by connecting the RadGrid to a WCF webservice. Everything works fine. Now I wanted to add a button column for deleting entries. I'd like to fire a server-side event by implementing the ItemCommand. So the code of my RadGrid looks as follows:
        <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True" 
            AutoGenerateColumns="False" GridLines="None"  
            onitemcommand="RadGrid1_ItemCommand"
            <MasterTableView DataKeyNames="Id" ClientDataKeyNames="Id"
                <Columns> 
                    <telerik:GridBoundColumn DataField="Firstname" HeaderText="Firstname" DataType="System.String"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Lastname" HeaderText="Lastname" DataType="System.String"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Age" HeaderText="Age" DataType="System.Int32"
                    </telerik:GridBoundColumn> 
                    <telerik:GridButtonColumn CommandName="Delete" Text="Delete" ImageUrl="~/Images/edit.png"  
                        UniqueName="column" DataTextField="Id" ButtonType="ImageButton"
                    </telerik:GridButtonColumn> 
                </Columns> 
                <PagerStyle Mode="Slider" /> 
            </MasterTableView> 
            <ClientSettings> 
                <DataBinding SelectMethod="GetSampleData" Location="Webservice/GridData.svc" SortParameterType="String"
                </DataBinding> 
            </ClientSettings> 
        </telerik:RadGrid> 

    The problem is that the ItemCommand event doesn't get fired unless I enable the "EnablePostBackOnRowClick" property on the ClientSettings. I don't like to do this however since then, every click on the row causes a postback which I don't really like.

    Can somebody give me a hint of what I'm doing wrong?

    Thx
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Oct 2009 Link to this post

    Hello Juri,

    As far as I know grid server events won't fire if we use client-side binding, unless we set the "EnablePostBackOnRowClick" property to true.
    So one suggestion is to delete the record is, attach a handler to grid's OnCommand client event and check for the commandname whether it is delete or not. If the commandname is delete, then delete the row, from radgrid and by calling the webservice method to delete as shown in demo.

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Juri Strumpflohner
    Juri Strumpflohner avatar
    2 posts
    Member since:
    Oct 2009

    Posted 13 Oct 2009 Link to this post

    Hmm..ok.

    So basically what you're telling me is that if you want to use ajax-enabled grid with client-side binding you have to do EVERYTHING over the webservice. Fetching data, deleting rows etc.

    Just for curiosity. Is there another way for gaining the client-side mechanisms such as asynchronous paging and data fetching (through webservice) and having actions etc. post back just normally to the server as you would expect from a standard ASP.net grid?

    But I guess this would lead to problems with the ASP.net postback+Viewstate architecture...having a button that posts back but wasn't there before..

    Thx again for your answer.

    Update:
    Alternatively, do you know how to retrieve the current row without using the OnRowSelected event. Basically if I have a GridTemplateColumn inside my grid (an edit button on each row for instance) like this
                    <telerik:GridTemplateColumn> 
                        <ItemTemplate> 
                            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/edit.png" CommandName="Edit" OnClientClick="commandEvent(); return false;" /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 

    The "commandEvent" is a JavaScript function which would then do further actions. Do you know how I can retrieve the client-side "DataItem" of the row on which the button has been pressed?

    Thx



  5. Riddhi Vora
    Riddhi  Vora avatar
    5 posts
    Member since:
    Oct 2009

    Posted 10 Dec 2009 Link to this post

    The source code snippet removed.
  6. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 15 Dec 2009 Link to this post

    Hi Riddhi,

     I reviewed the setup, and the code looks correct.
    If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and get back to you with additional information.


    Best wishes,
    Yavor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Riddhi Vora
    Riddhi  Vora avatar
    5 posts
    Member since:
    Oct 2009

    Posted 06 Apr 2010 Link to this post

    requesting you to please remove all the source code elements posted here ASAP.

    Thanks,
    Riddhi
  8. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 08 Apr 2010 Link to this post

    Hello Riddhi Vora,

    There are no code snippets supplied by you in this thread. Let me know which code snippet(s) you are referring to.

    Regards,
    Yavor
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Ali
    Ali avatar
    3 posts
    Member since:
    Sep 2014

    Posted 23 Sep 2014 in reply to Yavor Link to this post

    Can anyone solve my problem regarding issue on event OnItemCommand as it is not firing.
    Thanks in Advance
  10. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 25 Sep 2014 Link to this post

    Hi Ali,

    We will need additional information on your exact scenario, what the expected behavior is and what the actual issue is.

    Providing the markup and the relevant part of your code-behind will also prove helpful.

    Looking forward to your reply.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  11. Ali
    Ali avatar
    3 posts
    Member since:
    Sep 2014

    Posted 26 Sep 2014 in reply to Konstantin Dikov Link to this post

    Code is given and my Web UI version is 2014.1.225.45












     <telerik:RadGrid ID="BalanceAdjustment_RDGV" runat="server"  PageSize="7" 
                                            ShowStatusBar="true" AutoGenerateColumns="False"
                                            AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" OnInsertCommand="BalanceAdjustment_ItemCom" OnNeedDataSource="BalanceAdjustment_RDGV_NeedDataSource">
                                            <MasterTableView Width="100%" DataKeyNames="LOT_ID,TRAN_LOT_ID" AllowMultiColumnSorting="True">

                                                <Columns>
                                                    <telerik:GridBoundColumn SortExpression="LOT_ID" DataField="LOT_ID" Display="false">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn SortExpression="TRAN_LOT_ID" DataField="TRAN_LOT_ID" Display="false">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn HeaderText="Lot Num" DataField="LOT_NUM">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn HeaderText="Cust Name" DataField="CLIENT_NAME">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn HeaderText="Cust Code" DataField="CLIENT_CODE">
                                                    </telerik:GridBoundColumn>

                                                
                                                    <telerik:GridTemplateColumn DataField="TRAN_DATE" HeaderText="Trans Date" UniqueName="TRAN_DATE">

                                                        <ItemTemplate>
                                                            <telerik:RadDatePicker ID="transdate_cal" runat="server" DbSelectedDate='<%# Bind("TRAN_DATE") %>'
                                                                Enabled="false">
                                                            </telerik:RadDatePicker>
                                                        </ItemTemplate>

                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Start Value" UniqueName="STARTING_VALUE">
                                                        <ItemTemplate>
                                                            <telerik:RadTextBox ID="strt_value_tb" InputType="Number" runat="server" Text='<%# Eval("STARTING_VALUE") %>' Enabled="false">
                                                            </telerik:RadTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridBoundColumn HeaderText="Value Recv" DataField="VALUE_RECEIVED">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn HeaderText="Value Ship" DataField="VALUE_SHIPED">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn HeaderText="Transfer To" DataField="TRANSFER_TO">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn HeaderText="Ending Value" DataField="ENDING_VALUE">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Starting Balace" UniqueName="PCS_START_BAL">
                                                        <ItemTemplate>
                                                            <telerik:RadTextBox ID="pcs_start_bal_tb" InputType="Number" runat="server" Text='<%# Eval("PCS_START_BAL") %>' Enabled="false">
                                                            </telerik:RadTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="CTN Starting Bal" UniqueName="CTN_STARTING_BAL">
                                                        <ItemTemplate>
                                                            <telerik:RadTextBox ID="ctn_start_bal_tb" InputType="Number" runat="server" Text='<%# Eval("CTN_START_BAL") %>' Enabled="false">
                                                            </telerik:RadTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="right" HeaderText="Action" UniqueName="Action">
                                                        <HeaderStyle Width="120px" />
                                                        <ItemStyle Width="120px" />
                                                        <FooterStyle Width="120px" />
                                                        <ItemTemplate>
                                                            <asp:ImageButton ID="lnkUpdatePD" runat="server" align="right" CausesValidation="True" CommandName="UpdateGrid"
                                                                Height="20px" ImageUrl="~/images/update.png" ToolTip="Update" Visible="false" Width="20px" />
                                                            <asp:ImageButton ID="lnkCancelPD" runat="server" align="right" CausesValidation="False" CommandName="CancelGrid"
                                                                Height="20px" ImageUrl="~/images/Cancel.png" ToolTip="Cancel" Visible="false" Width="20px" />
                                                            <asp:ImageButton ID="lnkEditPD" runat="server" align="right" CausesValidation="False" CommandName="EditGrid"
                                                                Height="20px" ImageUrl="~/images/icon-edit.png" ToolTip="Edit" Width="20px" />
                                                        </ItemTemplate>

                                                    </telerik:GridTemplateColumn>
                                                </Columns>
                                            </MasterTableView>
                                        </telerik:RadGrid>
  12. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 30 Sep 2014 Link to this post

    Hello Ali,

    I have tested your RadGrid settings with dummy data and when I have attached a handler for the server-side OnItemCommand event, it fires as expected when you click on the button from the template column. Following is the sample that I have tested:
    <telerik:RadGrid ID="BalanceAdjustment_RDGV" runat="server" PageSize="7"
        ShowStatusBar="true" AutoGenerateColumns="true"
        AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" OnItemCommand="BalanceAdjustment_RDGV_ItemCommand"
        OnNeedDataSource="BalanceAdjustment_RDGV_NeedDataSource">
        <MasterTableView Width="100%" AllowMultiColumnSorting="True">
     
            <Columns>
                <telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="right" HeaderText="Action" UniqueName="Action">
                    <HeaderStyle Width="120px" />
                    <ItemStyle Width="120px" />
                    <FooterStyle Width="120px" />
                    <ItemTemplate>
                        <asp:ImageButton ID="lnkEditPD" runat="server" align="right" CausesValidation="False" CommandName="EditGrid"
                            Height="20px" ImageUrl="~/images/icon-edit.png" ToolTip="Edit" Width="20px" />
                    </ItemTemplate>
     
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    And the code-behind:
    protected void BalanceAdjustment_RDGV_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("ID", typeof(int));
        table.Columns.Add("FirstName", typeof(string));
        for (int i = 0; i < 5; i++)
        {
            table.Rows.Add(i, "FirstName" + i);
        }
     
        (sender as RadGrid).DataSource = table;
    }
     
    protected void BalanceAdjustment_RDGV_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "EditGrid")
        {
            // your custom logic
        }
    }

    If further assistance is needed, please elaborate on the exact issue and when do you expect the OnItemCommand to fire.

    Looking forward to your reply. 


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  13. Sahib
    Sahib avatar
    1 posts
    Member since:
    Apr 2015

    Posted 08 Apr 2015 Link to this post

    I have the same issue. But only on IE Edge. When I change my browser in compatibility mode to IE 8,9,10 it fires the item_Command event but when edge is selected it does not. Telerik Please do something and save my life. I have been struggling for it for more than 3 days. Googled alot but all in vain.
  14. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 13 Apr 2015 Link to this post

    Hello Sahib,

    I have tested the same example in IE 11 and the event is firing as expected on it too.

    Can you please inspect your browser's console and see if there are any JavaScript errors that could prevent the proper work of the control. Furthermore, please ensure that you are using version that support IE 11 in the first place.

    If the issue persists on your end, please open a regular support ticket and provide a sample, runnable project that replicates the problem, so we can test it locally.


    Best Regards,
    Konstantin Dikov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017