Disabled item image

4 posts, 2 answers
  1. Tia
    Tia avatar
    18 posts
    Member since:
    Mar 2013

    Posted 08 May 2013 Link to this post

    Hi,

    From client code, how to disable a Radmenu item and give a  disabled image on checking a Listbox item?

    Thanks for reply,
    Tia.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 May 2013 Link to this post

    Hi Tia,

    Please have a look at the following code.

    ASPX:
    <telerik:RadMenu ID="RadMenu1" runat="server">
        <Items>
            <telerik:RadMenuItem runat="server" Text="Mobiles">
                <Items>
                    <telerik:RadMenuItem runat="server" Text="Samsung">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadMenuItem>
            <telerik:RadMenuItem runat="server" Text="Cameras">
                <Items>
                    <telerik:RadMenuItem runat="server" Text="Canon">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadMenuItem>
        </Items>
    </telerik:RadMenu>
    <br />
    <br />
    <telerik:RadListBox ID="RadListBox" runat="server" CheckBoxes="true" OnClientItemChecked="OnClientItemChecked"
        Style="margin-top: 30px;">
        <Items>
            <telerik:RadListBoxItem runat="server" Text="Disable Samsung" />
        </Items>
    </telerik:RadListBox>

    JavaScript:
    <script type="text/javascript">
        function OnClientItemChecked(sender, args) {
            var menu = $find("<%= RadMenu1.ClientID %>");
            var menuItem = menu.findItemByText("Samsung");
            if (sender.findItemByText("Disable Samsung").get_checked() == true) {
                menuItem.disable();
                menuItem.set_imageUrl("../Images/Close.png");
            }
            else {
                menuItem.enable();
                menuItem.set_imageUrl("");
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tia
    Tia avatar
    18 posts
    Member since:
    Mar 2013

    Posted 22 May 2013 Link to this post

    Hi shinu,

    Thanks for the answer. I have another question. How can I add an expand direction image to root items?
  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 May 2013 Link to this post

    Hi Tia,

    You can set it from C# code as follows.

    C#:
    private void Page_PreRenderComplete(object sender, EventArgs e)
    {
        foreach (RadMenuItem item in RadMenu1.Items)
        {
            SetImageUrl(item);
        }
    }
     
    private void SetImageUrl(RadMenuItem item)
    {
        string imageUrl = "down";
        if (item.GroupSettings.ExpandDirection != UI.ExpandDirection.Auto)
        {
            imageUrl = item.GroupSettings.ExpandDirection.ToString().ToLower();
        }
     
        if (RadSkinManager.GetCurrent(this).Skin == "Black")
            imageUrl += "_black";
     
        item.ImageUrl = "Images/" + imageUrl + ".png";
    }

    Thanks,
    Shinu.
Back to Top