Set Checked Items On Client Side

3 posts, 0 answers
  1. barlas
    barlas avatar
    2 posts
    Member since:
    Mar 2014

    Posted 07 Mar 2014 Link to this post

    Hi,

    I use a combobox with checkboxes. I can get the checked values on the client side just I couldn't figure out how to set the checkboxes checked on client side. I know how to do it on serverside but we have a no-postback ajax enviroment and need to do this in client side.


    ddNewLocation combobox is databinded on page_load on server_side like below.

    ddNewLocation.DataSource = dr;
    ddNewLocation.DataBind();

    With the below code I could set the selectedindices but it doesn't check the checkboxes visually. How can I achieve this?


    var location = $find("<%= ddNewLocation.ClientID %>");
    var locations = JSON.parse(result.Message);
    for (var i = 0; i < locations.length; i++)
    {
    location._checkedIndices.push(locations[i].row_number);
    }

    Thanks. My Company has a paid account but I didnt have time to find the username and password.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Mar 2014 in reply to barlas Link to this post

    Hi barlas,

    Please have a look into the sample code snippet which works fine at my end. Let me know if you have any concern.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true">
    </telerik:RadComboBox>
    <telerik:RadButton ID="RadButton1" runat="server" Text="CheckItem" OnClientClicked="OnClientClicked" AutoPostBack="false">
    </telerik:RadButton>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadComboBox1.DataSourceID = "SqlDataSource1";
        RadComboBox1.DataTextField = "Name";
        RadComboBox1.DataValueField = "ID";
        RadComboBox1.DataBind();
    }

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked(sender, args) {
            var combo = $find("<%=RadComboBox1.ClientID %>");
            combo.findItemByValue("1").set_checked(true);
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. barlas
    barlas avatar
    2 posts
    Member since:
    Mar 2014

    Posted 07 Mar 2014 in reply to Shinu Link to this post

    Thanks Shinu,

    This is exactly what I was looking for. I was out of my way trying to find a solution as seen in the code I posted.

    Thanks again.
Back to Top