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

ItemCommand not firing

2 Answers 75 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 17 Apr 2013, 12:29 PM
I have looked at probably all of the previous articles that return in a search fr this issue but none of them are quite like my problem so I am posting a new thread on it. In my thread found HERE , I was having an issue getting a new window to open using a GridButtonColumn. I used ItemCommand to get some data from my radgrid and store it in session. Then to open the new window I added the OnItemDataBound event. Once I added OnItemDataBound, the ItemCommand event no longer fires. If I remove OnItemDataBound, the ItemCommand even will fire again as expected. I need to have this functionality so it is my understanding that I need them both, any ideas?

Telerik version:
2012.2.912.40


<telerik:RadGrid ID="policeGrid" runat="server" AllowSorting="false" Skin="Default" OnNeedDataSource="LoadPoliceTable" OnItemCommand="policeGrid_ItemCommand"
               GridLines="Both" AutoGenerateColumns="False" ShowFooter="false" AllowPaging="true"  AllowFilteringByColumn="true"
               PageSize="25" PagerStyle-AlwaysVisible="true" OnUpdateCommand="policeGrid_UpdateCommand" OnInsertCommand="policeGrid_InsertCommand"
               EnableLinqExpressions="false" OnDeleteCommand="policeGrid_DeleteCommand" GroupingEnabled="True" ShowGroupPanel="True" OnItemDataBound="policeGrid_ItemDataBound"
               GroupPanel-Enabled="True">
               <ClientSettings AllowDragToGroup="True"/>
               <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="TopAndBottom" />
               <MasterTableView AllowMultiColumnSorting="true" CommandItemDisplay="Top" DataKeyNames="station_id"
                   NoMasterRecordsText="No current police." TableLayout="Fixed" CommandItemSettings-ShowRefreshButton="False">
                   <RowIndicatorColumn Visible="False">
                       <HeaderStyle Width="20px"></HeaderStyle>
                   </RowIndicatorColumn>
                   <Columns>
                       <telerik:GridEditCommandColumn UniqueName="btnEdit" ButtonType="ImageButton" EditText="Edit" Resizable="False" >
                           <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                           <HeaderStyle Width="15px" />
                       </telerik:GridEditCommandColumn>
                       <telerik:GridButtonColumn UniqueName="infoPolice" ButtonType="ImageButton" ImageUrl="../../RadControls/Grid/Skins/info.png" CommandName="Select" Text="Info">
                           <HeaderStyle Width="15px" />
                       </telerik:GridButtonColumn>
                       <telerik:GridBoundColumn DataField="STATION_ID" HeaderText="STATION_ID" UniqueName="STATION_ID"
                           AllowFiltering="True" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" >
                           <HeaderStyle Width="50px" />
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="PRIMARY_CONTACT_ID" HeaderText="PRIMARY_CONTACT_ID" UniqueName="PRIMARY_CONTACT_ID"
                           AllowFiltering="True" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" >
                           <HeaderStyle Width="50px" />
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="STATE_NAME" HeaderText="STATE_NAME" UniqueName="STATE_NAME"
                           AllowFiltering="True" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" >
                           <HeaderStyle Width="75px" />
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="TROOP" UniqueName="TROOP" HeaderText="TROOP"
                           AllowFiltering="True" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false">
                           <HeaderStyle Width="75" />
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="PH_HAZMAT" HeaderText="PH_HAZMAT" UniqueName="PH_HAZMAT"
                           AllowFiltering="True" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false">
                           <HeaderStyle Width="75px" />
                       </telerik:GridBoundColumn>
                       <telerik:GridButtonColumn ConfirmText="Delete this group?" ConfirmDialogType="RadWindow"
                           ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                           UniqueName="DeleteColumngroups" Visible="true">
                           <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                           <HeaderStyle Width="50px" />
                       </telerik:GridButtonColumn>
                   </Columns>
                   <EditFormSettings UserControlName="EditPolice.ascx" EditFormType="WebUserControl">
                       <EditColumn UniqueName="EditCommandColumn1">
                       </EditColumn>
                   </EditFormSettings>
               </MasterTableView>
           </telerik:RadGrid>

protected void policeGrid_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
               var stationId = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["station_id"];
               Session["station_id"] = stationId;             
            }           
        }
 
        protected void policeGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                ImageButton link = (ImageButton)item["infoPolice"].Controls[0];
                link.OnClientClick = "Open();return false;";
            }
        }

2 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 17 Apr 2013, 12:58 PM
it would appear that the code in the OnItemDataBound event is overwriting the default functionality of the GridButton. instead of firing the ItemCommand event as prescribed by default it is only firing the onClientClick. Anyone have a work-around?
0
Shinu
Top achievements
Rank 2
answered on 18 Apr 2013, 05:32 AM
Hi,

One suggestion is that you can pass the CommandArgument for the buttoncolumn as shown below.
C#:
protected void policeGrid_ItemCommand(object sender, GridCommandEventArgs e)
{
            if (e.CommandArgument == "Your argument")
            {
            }
}

Thanks,
Shinu
Tags
General Discussions
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or