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

FindItemByValue failed for RadMenuItem within the RadGrid

2 Answers 130 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Dinesh
Top achievements
Rank 1
Dinesh asked on 03 Feb 2011, 02:11 PM
Hi,

I have created a RadMenu in a RadGridTemplate column so that each row will have a RadMenu. I need to view/hide that RadMenu items acording to the permission.

What i did is I try to find the RadMenuItem in Grid_ItemDataBound event of the grid.

First I use  "FindItemByText" method. It works well.
  
 var radMenuMission = item.FindControl(RadMenuName) as RadMenu;                  
  
if (radMenuMission != null)                     {
     var radMenuItem = radMenuMission.FindItemByText(
"Delete");

But the problem is Text property is changed according to localized resources.
in that way Finding the RadMenuItem by Text is failed.

I need to use "FindItemByValue" method. I set "Value" attribute of the  RadMenuItem still i cant Find the menu Item. 

When I see the html code of the browser the Value property is missing.

Can anybody help for this ?

Thank you,

Dinesh

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Feb 2011, 06:06 AM
Hello Dinesh,

I have tried the similar scenario and that worked fine at my end. Here I am pasting my code and please do a double check with your code.:
aspx:
<telerik:GridTemplateColumn  HeaderText="Menu"  UniqueName="Menu">
  <ItemTemplate>
     <telerik:RadMenu ID="RadMenu2" runat="server" Skin="Black">
         <Items>
              <telerik:RadMenuItem runat="server" Text="RadMenuItem1" Value="1">
              </telerik:RadMenuItem>
              <telerik:RadMenuItem runat="server" Text="Root RadMenuItem2">
              </telerik:RadMenuItem>
              <telerik:RadMenuItem runat="server" Text="Root RadMenuItem3">
              </telerik:RadMenuItem>
        </Items>
     </telerik:RadMenu>
  </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
           var radMenuMission = item.FindControl("RadMenu2") as RadMenu;
           if (radMenuMission != null)
           {
               var radMenuItem = radMenuMission.FindItemByValue("1");
           }
   }

Thanks,
Shinu.
0
Dinesh
Top achievements
Rank 1
answered on 08 Feb 2011, 05:58 AM
Hi Shinu,

Thank you for your quick response. It is working now. The problem was in Localization Resource. When we generate resource from VS it localize "Value" attribute too. Then it override the value we set.

Thanks

Dinesh 
Tags
Menu
Asked by
Dinesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Dinesh
Top achievements
Rank 1
Share this question
or