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

Set Checked Items On Client Side

2 Answers 603 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
barlas
Top achievements
Rank 1
barlas asked on 07 Mar 2014, 08:51 AM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Mar 2014, 10:13 AM
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.
0
barlas
Top achievements
Rank 1
answered on 07 Mar 2014, 11:11 AM
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.
Tags
ComboBox
Asked by
barlas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
barlas
Top achievements
Rank 1
Share this question
or