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

RadMenu conditional disable

1 Answer 49 Views
Menu
This is a migrated thread and some comments may be shown as answers.
steven schmalfeld
Top achievements
Rank 2
steven schmalfeld asked on 22 Sep 2015, 05:45 PM

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;     } }​

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 25 Sep 2015, 01:31 PM
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
Tags
Menu
Asked by
steven schmalfeld
Top achievements
Rank 2
Answers by
Ivan Danchev
Telerik team
Share this question
or