Not able to Enable/Disable commanditem buttons of telerik radgrid (telerik version 2008.3.1314.20)

2 posts, 0 answers
  1. Sankeerthi
    Sankeerthi avatar
    1 posts
    Member since:
    Mar 2016

    Posted 02 Mar 2016 Link to this post

    I have radgrid, with 3 command buttons(Edit, Save and Cancel)

    On Edit click Save and cancel buttons should be visible. (By default they should be disabled)

    after Save or Cancel click grid goes to read only mode and only Edit command button should be displayed.

    i tried all the possibilities by finding the command button and disabling it. Though there is no exception or anything still couldn't achieve this functionality.

    Please help me is needed immediately.

    CODE :

      <telerik:RadGrid ID="gridMilitaryPension" runat="server" AutoGenerateColumns="false" AllowMultiRowEdit="true"  RenderMode="lightweight"
                         Skin="Office2007" PagerStyle-Mode="NextPrevAndNumeric" AllowPaging="True" PageSize="30" OnNeedDataSource="gridMilitaryPension_NeedDataSource"
                          OnItemCommand="gridMilitaryPension_ItemCommand" >
                            <MasterTableView CommandItemDisplay="Top" EditMode="InPlace" Font-Size="10pt">                          
                                     <telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="ID" Display="true" ReadOnly="True"

                                     <telerik:GridBoundColumn UniqueName="slottype" DataField="slottype" HeaderText="Slot Type" SortExpression="slottype" ReadOnly="True"
                                     <telerik:GridTemplateColumn DataField="total" UniqueName="total" HeaderText="Total Seats" SortExpression="total">
                                            <asp:Label ID="lblTotalSeats" runat="server" Text='<%# Eval("total") %>' class="classLblTotal"></asp:Label>
                                            <asp:TextBox ID="txtTotalSeats" runat="server" Text='<%# Eval("total") %>' Width="100%"  class='<%# Eval("slottype") %>'  onblur="addition(this)" onchange="DataChanged(this)"></asp:TextBox>

                                             <td> <asp:Button runat="server" ID="btnSaveAllChanges" Text="Save All Changes"  CommandName="SaveAllChanges"  /></td>
                                             <td> <asp:Button runat="server" ID="btnCancel" Text="Cancel"  CommandName="Cancel" /></td>
                                             <td> <asp:Button runat="server" ID="btnEdit" Text="Edit Total Seats" CommandName="Edit"  onclick="btnEdit_Click"/></td>




    In code Behind:

     protected void gridMilitaryPension_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
                if (e.CommandName == "Edit")

    //Below i am capturing the controls and trying to hide/unhide. used visible property also but no luck
                    GridCommandItem cmditem = (GridCommandItem)e.Item;
                    Button btnSaveAllChanges = cmditem.FindControl("btnSaveAllChanges") as Button;
                    Button btnCancel = cmditem.FindControl("btnCancel") as Button;
                    Button btnEdit = cmditem.FindControl("btnEdit") as Button;
                    btnSaveAllChanges.Enabled = true;
                    btnCancel.Enabled = true;
                    btnEdit.Enabled = false;            
                if (e.CommandName == "SaveAllChanges")
                   //after logic, Edit button should be enabled.

                if (e.CommandName == "Cancel")


  2. Konstantin Dikov
    Konstantin Dikov avatar
    2115 posts

    Posted 07 Mar 2016 Link to this post

    Hi Sankeerthi,

    The ItemCommand event fires for GridDataItem objects and in order to get reference to the GridCommandItem you should use the following line instead:
    GridCommandItem cmditem = gridMilitaryPension.MasterTableView.GetItems(GridItemType.CommandItem)[0] as GridCommandItem;

    As for enabling/disabling the buttons within the GridCommandItem you should do that within the PreRender event of the grid or within the OnItemCreated/OnItemDataBound events, because after OnItemCommand event fires, the RadGrid will rebind and you will lose the customization over the buttons.

    Please note that you may have to use global flags to determine whether to disable or enable the buttons, where the flags could be set in your custom events.

    Finally, keep in mind that version 2008 is not supported and it is highly recommended that you upgrade to newer version.

    Hope this helps.

    Konstantin Dikov
    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 Feedback Portal and vote to affect the priority of the items
Back to Top