Check Rad List box Item check box if user click on the Item text

9 posts, 1 answers
  1. Prasad
    Prasad avatar
    40 posts
    Member since:
    Sep 2011

    Posted 04 Feb 2013 Link to this post

    Hi 
         I have a radlistbox item with check boxes. User can successfully Check and unchecked the items . Can i check if user click on the Item text, Unchecked if User again click on the Item text.  Please provide your valuable  Suggestion. ASAP
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Feb 2013 Link to this post

    Hi Prasad,

    I was able to do your requirement on double click.Try the following code snippet and let me know your concern
    aspx:
    <telerik:RadListBox ID="RadListBox1" runat="server" CheckBoxes="true" OnClientItemDoubleClicking="OnClientItemDoubleClicking"
        <Items>
    .................................
        </Items>
    </telerik:RadListBox>
    JS:
    <script type="text/javascript">
        function OnClientItemDoubleClicking(sender, args)
        {
            if (args.get_item().get_checked() == false)
            {
                args.get_item().set_checked(args.get_item().get_selected());
            }
            else
            {
                args.get_item().set_checked(false);
            }
        }
    </script>

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sean O'Brien
    Sean O'Brien avatar
    3 posts
    Member since:
    Jul 2009

    Posted 01 Mar 2013 Link to this post

    Prasad,

    I achieved the functionality on single click using the OnClientSelectedIndexChanging event. Otherwise basically the same as the above recommendation. You might want to disable selecting so that it fires each time: args.set_cancel(true);

    Also, in the first set_checked(...); call in Princy's version I'd just pass true.

    Peace.
  5. Sean O'Brien
    Sean O'Brien avatar
    3 posts
    Member since:
    Jul 2009

    Posted 01 Mar 2013 Link to this post

    P.S. Basically, something like this:

            function OnClientItemSelectedIndexChanging(sender, args) {
                if (args.get_item().get_checked() == false) {
                    args.get_item().set_checked(true);
                }
                else {
                    args.get_item().set_checked(false);
                }
                args.set_cancel(true);
            }
  6. John
    John avatar
    14 posts
    Member since:
    Jun 2013

    Posted 18 Oct 2013 Link to this post

    Hi,

    I have a similar problem but I want the checkbox to be checked when the user clicks on an items text, index change doesn't work for me if you re-click on an item you've reindexed too.

    i.e.
    click on item, change index sets checkbox,
    reclick on same item, change index doesn't fire as the index hasn't changed.

    my requirements
    click on item, set/unset checkbox depending on current value
    click on item again to set, set/unset checkbox depending on current value

    any help would be great as i can't seem to find a solution to allow me to do this and the onclientonclicked isn't available

    thanks,
    JC
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Oct 2013 Link to this post

    Hi John,

    The following code snippet works fine at my end. But please note that it will change the default behaviour of the CheckBox. So you should write CheckBox checked logic inside 'OnClientItemChecked'.

    ASPX:
    <telerik:RadListBox ID="RadListBox1" runat="server" CheckBoxes="true" AutoPostBack="true"
        OnPreRender="RadListBox1_PreRender">
        <Items>
            <telerik:RadListBoxItem Text="Item1" runat="server" Value="1" />
            <telerik:RadListBoxItem Text="Item2" runat="server" Value="2" />
            <telerik:RadListBoxItem Text="Item3" runat="server" Value="3" />
        </Items>
    </telerik:RadListBox>

    C#:
    protected void RadListBox1_PreRender(object sender, EventArgs e)
    {
        foreach (RadListBoxItem item in RadListBox1.Items)
        {
            item.Attributes.Add("onclick", "CellClick('" + item.Text + "','" + item.Value + "');");
        }
    }

    JavaScript:
    <script type="text/javascript">
        function CellClick(text, value) {
            //it will fire whenever you are clicking on the item text
            //write your code
            var list = $find("<%=RadListBox1.ClientID %>");
            list.findItemByValue(value).set_checked(!list.findItemByValue(value).get_checked());
        }
        function OnClientItemChecked1(sender, args) {
            args.get_item().set_checked(!args.get_item().get_checked());
        }
    </script>

    Thanks,
    Princy.
  8. Sean O'Brien
    Sean O'Brien avatar
    3 posts
    Member since:
    Jul 2009

    Posted 18 Oct 2013 Link to this post

    John,
    
    I have a RadListBox that updates its checkbox column state based on clicking the list items and I made it work properly with OnClientItemSelectedIndexChanging. Something like this:

    function OnClientItemSelectedIndexChanging(sender, args) {
      var item = args.get_item();
      item.set_checked(!item.get_checked());
      args.set_cancel(true);
    }
  9. Julian
    Julian avatar
    1 posts
    Member since:
    Feb 2011

    Posted 20 Oct 2013 Link to this post

    Hi Sean,

    Thanks that's perfect, We've got the required functionality working ok

    Thanks again,

  10. Prajakta
    Prajakta avatar
    1 posts
    Member since:
    Aug 2014

    Posted 07 Aug 2014 in reply to Sean O'Brien Link to this post

    Thanks a lot for this solution worked for me

    I was also facing same problem its solved using above code

    Thank you for same

    But before using the above code the item was getting selected when i click on checkbox not on its associated text
    which solved now 
    but now the problem is now its getting selected when clicked on associated text but viceversa is not working means its not  getting selected when i click on check box in my scenario both should work
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017