How to restrict uncheck option from radlistbox

4 posts, 0 answers
  1. suresh
    suresh avatar
    30 posts
    Member since:
    Apr 2011

    Posted 19 Feb 2012 Link to this post

    Hi there,
     I'm using RadListBox with checkboxes=true..By default I have loading the items and some of the items have checked..I need to restrict  uncheck option for checked items.How can i achieve this?.

       Thanks,
    Suresh.S

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Feb 2012 Link to this post

    Hello,

    One suggestion is to try setting the checked items as disabled on OnClientLoad event.
    JS:
    function OnClientLoad(sender, args)
     {
       for (i = 0; i < sender.get_checkedItems().length; i++)
        {
            sender.get_checkedItems()[i].disable();
        }
     }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. suresh
    suresh avatar
    30 posts
    Member since:
    Apr 2011

    Posted 21 Feb 2012 Link to this post

    Thanks princy..I don't need to disable an item.Because I have to do something in OnselectedIndexChanged of an item..By default all items are checked..I need to restrict uncheck option for that checkboxes(i.e readonly or something else..)..

    Thanks,
    Suresh
  5. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 22 Feb 2012 Link to this post

    Suresh:

    Have you tried attaching a JavaScript function to the RadListBox's OnClientItemChecking event?

    Since the checked state returned by the item's get_checked() function is not yet changed to reflect the new value, you can cancel the attempt to toggle it.

    Default.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </scripts>
        </telerik:RadScriptManager>
        <script type="text/javascript">
            function OnClientItemCheckingHandler(sender, eventArgs) {
                var item = eventArgs.get_item();
                var message = "You are not allowed to ";
                message += item.get_checked() ? "uncheck" : "check";
                message += " the item " + item.get_text();
                alert(message);
                eventArgs.set_cancel(true);
            }
        </script>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <div>
            <div class="title">
                Checkboxes only:</div>
            <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">
                <div class="list-panel">
                    <telerik:RadListBox ID="RadListBox1" runat="server" CheckBoxes="true" Width="200px"
                        Height="300px" OnClientItemChecking="OnClientItemCheckingHandler">                  
                        <items>
                            <telerik:RadListBoxItem Text="Arts" />
                            <telerik:RadListBoxItem Text="Biographies" Checked="true" />
                            <telerik:RadListBoxItem Text="Children's Books" />
                            <telerik:RadListBoxItem Text="Computers � Internet"/>
                            <telerik:RadListBoxItem Text="Cooking" Checked="true" />
                            <telerik:RadListBoxItem Text="History" />
                            <telerik:RadListBoxItem Text="Fiction" />
                            <telerik:RadListBoxItem Text="Mystery" Checked="true" />
                            <telerik:RadListBoxItem Text="Nonfiction" />
                            <telerik:RadListBoxItem Text="Romance" />
                            <telerik:RadListBoxItem Text="Science Fiction " />
                            <telerik:RadListBoxItem Text="Travel" />
                        </items>
                    </telerik:RadListBox>
                    <asp:Button ID="Button1" runat="server" Text="Get Checked Items!" CssClass="qsfButtonBigger"
                        OnClick="Button1_Click" />
                    <div class="module">
                        <strong>Checked Items:</strong>
                        <br />
                        <br />
                        <asp:Label ID="itemsClientSide" runat="server" BorderStyle="None" CssClass="text" />
                    </div>
                </div>
            </telerik:RadAjaxPanel>
        </div>
        </form>
    </body>
    </html>

    Hope this helps!
Back to Top