This is a migrated thread and some comments may be shown as answers.

ItemCommand event not firing

14 Answers 1883 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Juri Strumpflohner
Top achievements
Rank 1
Juri Strumpflohner asked on 12 Oct 2009, 02:50 PM
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

14 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 13 Oct 2009, 06:42 AM
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.
0
Juri Strumpflohner
Top achievements
Rank 1
answered on 13 Oct 2009, 11:03 AM
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



0
Riddhi Vora
Top achievements
Rank 1
answered on 10 Dec 2009, 08:02 AM
The source code snippet removed.
0
Yavor
Telerik team
answered on 15 Dec 2009, 10:40 AM
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.
0
Riddhi Vora
Top achievements
Rank 1
answered on 06 Apr 2010, 01:17 PM
requesting you to please remove all the source code elements posted here ASAP.

Thanks,
Riddhi
0
Yavor
Telerik team
answered on 08 Apr 2010, 12:59 PM
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.
0
Ali
Top achievements
Rank 1
answered on 23 Sep 2014, 12:00 PM
Can anyone solve my problem regarding issue on event OnItemCommand as it is not firing.
Thanks in Advance
0
Konstantin Dikov
Telerik team
answered on 25 Sep 2014, 02:12 PM
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.

 
0
Ali
Top achievements
Rank 1
answered on 26 Sep 2014, 10:11 AM
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>
0
Konstantin Dikov
Telerik team
answered on 30 Sep 2014, 08:50 AM
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.

 
0
Sahib
Top achievements
Rank 1
answered on 08 Apr 2015, 04:19 PM
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.
0
Konstantin Dikov
Telerik team
answered on 13 Apr 2015, 07:27 AM
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.

 
0
Zandi
Top achievements
Rank 1
answered on 29 Dec 2016, 09:05 AM

Hi all, although it is old post I can see there are some issues with RadGrid OnItemCommand event not firing in other posts so I'll post mine problem/solution also.

Scenario: Button inside GridButtonColumn with CommandName which when fired does some logic.

Problem: The method that supposed to execute on button event(click) was not executing at all. 

Solution: Change in Page_Load in code behind because there was some logic which was handling what to do when Page.IsPostBack. After "better" defining what to do on postback everything worked as expected.

So, try reviewing where and if you are using Page.IsPostBack and if changing it solves you problems.

Best regards.

 

0
Mary
Top achievements
Rank 1
answered on 13 Dec 2017, 08:53 PM
Yippee Zandi!!! I was having the same issue and in this case it was code in the Page_Init - wrapped that in an if (!IspostBack) and all was well
Tags
Grid
Asked by
Juri Strumpflohner
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Juri Strumpflohner
Top achievements
Rank 1
Riddhi Vora
Top achievements
Rank 1
Yavor
Telerik team
Ali
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Sahib
Top achievements
Rank 1
Zandi
Top achievements
Rank 1
Mary
Top achievements
Rank 1
Share this question
or