RadMenu conditional disable

2 posts, 0 answers
  1. steven schmalfeld
    steven schmalfeld avatar
    9 posts
    Member since:
    Dec 2006

    Posted 22 Sep 2015 Link to this post

    I have a RadMenu linked to a RadGrid. If a row in the grid contains a certain value I want to allow/disallow menu items. For example, if a row has a trasnaction type of payment and the field reversed is not true, I do now want to give the user the option "Reverse Payment"

    This is my Javascript:

        function RowContextMenu(sender, eventArgs) {         var menu = $find("<%=RadMenu1.ClientID %>");         var evt = eventArgs.get_domEvent();         if (evt.target.tagName == "INPUT" || evt.target.tagName == "A")         {             return;         }         var index = eventArgs.get_itemIndexHierarchical();         document.getElementById("radGridClickedRowIndex").value = index;         sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);         menu.show(evt);         evt.cancelBubble = true;         evt.returnValue = false;         if (evt.stopPropagation)         {             evt.stopPropagation();             evt.preventDefault();         }     }

     This is my grid aspx code:

     

    <telerik:RadGrid ID="RadGrid1" runat="server"Width="100%"  Height="205px"  AllowPaging="false"                                                                                                   AllowSorting="true"  DataSourceID="SqlDataSource1" OnItemDataBound="RadGrid1_ItemDataBound"GroupPanelPosition="Top" AutoGenerateColumns="False" CellSpacing="-1" GridLines="Both" Font-Size="Smaller" ><ClientSettings AllowColumnsReorder="True"><Scrolling AllowScroll="True" UseStaticHeaders="True" />                                     </ClientSettings><MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="ID,TransactionID" ><Columns>                                         <telerik:GridBoundColumn DataField="ID" Display="false" DataType="System.Int32" FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True" SortExpression="ID" UniqueName="ID"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="LoanID" Display="false" FilterControlAltText="Filter LoanID column" HeaderText="LoanID" SortExpression="LoanID" UniqueName="LoanID"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="LoanSeq" DataType="System.Int32" Display="false" FilterControlAltText="Filter LoanSeq column" HeaderText="LoanSeq" SortExpression="LoanSeq" UniqueName="LoanSeq"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="SequenceID" FilterControlAltText="Filter SequenceID column" HeaderText="Loan" SortExpression="SequenceID" UniqueName="SequenceID"><HeaderStyle Width="60px" /><ItemStyle Width="60px" /></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="BusinessDate" DataType="System.DateTime" FilterControlAltText="Filter BusinessDate column" HeaderText="BusinessDate" SortExpression="BusinessDate" UniqueName="BusinessDate" DataFormatString="{0:MM/dd/yyyy}"><HeaderStyle Width="80px" /><ItemStyle Width="80px" /></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="TotalDue" DataType="System.Decimal" FilterControlAltText="Filter TotalDue column" HeaderText="TotalDue" SortExpression="TotalDue" UniqueName="TotalDue" DataFormatString="{0:f2}"><HeaderStyle Width="60px" /><ItemStyle Width="60px" /></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Total" DataType="System.Decimal" FilterControlAltText="Filter Total column" HeaderText="Total" SortExpression="Total" UniqueName="Total" DataFormatString="{0:f2}"><HeaderStyle Width="60px" /><ItemStyle Width="60px" /></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="MiscCharge" DataType="System.Decimal" FilterControlAltText="Filter MiscCharge column" HeaderText="MiscChg" SortExpression="MiscCharge" UniqueName="MiscCharge" DataFormatString="{0:f2}"><HeaderStyle Width="70px" /><ItemStyle Width="70px" /></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="LateFees" DataType="System.Decimal" FilterControlAltText="Filter LateFees column" HeaderText="LateFees" SortExpression="LateFees" UniqueName="LateFees" DataFormatString="{0:f2}"><HeaderStyle Width="60px" /><ItemStyle Width="60px" /></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="ToPrincipal" DataType="System.Decimal" FilterControlAltText="Filter ToPrincipal column" HeaderText="ToPrincipal" SortExpression="ToPrincipal" UniqueName="ToPrincipal" DataFormatString="{0:f2}"><HeaderStyle Width="70px" /><ItemStyle Width="70px" /></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Balance" DataType="System.Decimal" FilterControlAltText="Filter Balance column" HeaderText="Balance" SortExpression="Balance" UniqueName="Balance" DataFormatString="{0:f2}"><HeaderStyle Width="60px" /><ItemStyle Width="60px" /></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="EditBy" FilterControlAltText="Filter EditBy column" HeaderText="EditBy" SortExpression="EditBy" UniqueName="EditBy"><HeaderStyle Width="40px" /><ItemStyle Width="40px" /></telerik:GridBoundColumn>                                         <telerik:GridBoundColumn DataField="Status"  Display="True" FilterControlAltText="Filter Status column" HeaderText="Status" SortExpression="Status" UniqueName="Status"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Comments" FilterControlAltText="Filter Comments column" HeaderText="Comments" SortExpression="Comments" UniqueName="Comments">                             <HeaderStyle Width="180px" /><ItemStyle Width="180px" />                                                                                    </telerik:GridBoundColumn><telerik:GridBoundColumn DataField="TransactionID" DataType="System.Int32" Display="False" FilterControlAltText="Filter TransactionID column" HeaderText="TransactionID" ReadOnly="True" SortExpression="TransactionID" UniqueName="TransactionID"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="PaymentNumber" DataType="System.Int32" Display="False" FilterControlAltText="Filter PaymentNumber column" HeaderText="PaymentNumber" SortExpression="PaymentNumber" UniqueName="PaymentNumber"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="TransType" Display="False" FilterControlAltText="Filter TransType column" HeaderText="TransType" SortExpression="TransType" UniqueName="TransType"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="CheckNumber" DataType="System.Int32" Display="False" FilterControlAltText="Filter CheckNumber column" HeaderText="CheckNumber" SortExpression="CheckNumber" UniqueName="CheckNumber"></telerik:GridBoundColumn><telerik:GridCheckBoxColumn DataField="Reversed" DataType="System.Boolean" Display="False" FilterControlAltText="Filter Reversed column" HeaderText="Reversed" SortExpression="Reversed" UniqueName="Reversed"></telerik:GridCheckBoxColumn><telerik:GridBoundColumn DataField="Refunds" DataType="System.Decimal" Display="False" FilterControlAltText="Filter Refunds column" HeaderText="Refunds" SortExpression="Refunds" UniqueName="Refunds"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="OfficeID" DataType="System.Int32" Display="False" FilterControlAltText="Filter OfficeID column" HeaderText="OfficeID" SortExpression="OfficeID" UniqueName="OfficeID"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="CDTransactionID" DataType="System.Int32" Display="False" FilterControlAltText="Filter CDTransactionID column" HeaderText="CDTransactionID" SortExpression="CDTransactionID" UniqueName="CDTransactionID"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Principal" DataType="System.Decimal" Display="False" FilterControlAltText="Filter Principal column" HeaderText="Principal" SortExpression="Principal" UniqueName="Principal"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="EditDate" DataType="System.DateTime" Display="False" FilterControlAltText="Filter EditDate column" HeaderText="EditDate" SortExpression="EditDate" UniqueName="EditDate" DataFormatString="{0:MM/dd/yyyy}"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="PriorBalance" DataType="System.Decimal" Display="False" FilterControlAltText="Filter PriorBalance column" HeaderText="PriorBalance" SortExpression="PriorBalance" UniqueName="PriorBalance"></telerik:GridBoundColumn></Columns>                                     <ItemStyle Height="10px" Font-Size=".9em" />                                     <HeaderStyle Height="12px" Font-Size=".9em" />                                     <FilterItemStyle Height="12px" Font-Size=".9em"/>                                     <HeaderStyle Height="12px" Font-Size=".9em" /></MasterTableView>                                         <ClientSettings>                                             <ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>                                             <Selecting AllowRowSelect="true" />                                         </ClientSettings></telerik:RadGrid>​

     

     

    Finally, this is the code-behind:

     

    protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e) {     int radGridClickedRowIndex;     int radGridClickedItemIndex;     radGridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"]);          int TranID = 0;     switch (e.Item.Text)     {         case "Reverse Payment":             radGridClickedItemIndex = (int)RadGrid1.Items[radGridClickedRowIndex].ItemIndex;             TranID = Convert.ToInt32(RadGrid1.MasterTableView.DataKeyValues[radGridClickedItemIndex]["TransactionID"]);             ShowReversePayment(TranID);             //RadGrid1.Rebind();             break;     } }​

     

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    835 posts

    Posted 25 Sep 2015 Link to this post

    Hello,

    Please, find linked the RadMenuItem Object documentation article, which demonstrates how you can disable/enable particular MenuItems using the MenuItem object's disable() and enable() client-side methods.

    Regards,
    Ivan Danchev
    Telerik
    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top