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

How to set Checked Values?

3 Answers 636 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 03 Nov 2011, 08:51 PM
I am trying to figure out how to set Checked values in a databound Combobox, using the Q2-2011 version of the control - as seen in this demo:
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/checkboxes/defaultvb.aspx

the code below does not seem to be setting the checked values correctly, specifically this line: 

UDFControl.FindItemByValue(tItem).Checked = 
True

The scenario - I am inserting RadComboBoxes into a Placeholder in a Repeater on ItemCreated.  This all works great, I get the comboboxes, the data shows up in the drop down, and I have the Checkboxes, can multi-select, etc.  I just can't seem to set the initial values with the .checked = true

col1.DataType = GetType(String)
col2.DataType = GetType(String)
tData.Columns.Add(col1)
tData.Columns.Add(col2)
 
Dim tCodes As String() = UDF_Data.Rows(currentIndex)("Codes").ToString.Split(uSVM)
Dim tDescriptions As String() = UDF_Data.Rows(currentIndex)("Descriptions").ToString.Split(uSVM)
 
For i = 0 To tCodes.Count - 1
    Dim row As DataRow = tData.NewRow
    row(col1) = tCodes(i)
    row(col2) = tDescriptions(i)
    tData.Rows.Add(row)
Next
 
Dim UDFControl As New Telerik.Web.UI.RadComboBox
UDFControl.ID = UDF_Data.Rows(currentIndex)("ID").ToString.Replace("*", "_")
e.Item.FindControl("UDF").Controls.Add(UDFControl)
UDFControl.DataSource = tData
UDFControl.DataTextField = "Desc"
UDFControl.DataValueField = "ID"
UDFControl.DataBind()
UDFControl.Width = "204"
 
UDFControl.CheckBoxes = True
UDFControl.EnableCheckAllItemsCheckBox = True
UDFControl.EmptyMessage = "Select One or More Values"
Dim tValues As String() = UDF_Data.Rows(currentIndex)("Value").ToString.Split(uSVM)
For Each tItem As String In tValues
    If UDFControl.FindItemByValue(tItem) IsNot Nothing Then
        UDFControl.FindItemByValue(tItem).Checked = True
    End If
Next

Any ideas?

I understand this is a new feature of the Combobox and can't seem to find any examples of how this should be done.

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Nov 2011, 02:39 PM
Hello,

<telerik:RadComboBox ID="RadComboBox1" runat="server"></telerik:RadComboBox>

protected void Page_Load(object sender, EventArgs e)
    {
         
        DataTable dt = new DataTable();
        dt.Columns.Add("ID",typeof(string));
        dt.Columns.Add("Description", typeof(string));
        dt.Rows.Add("1","aaa");
        dt.Rows.Add("2","bbb");
        dt.Rows.Add("3","ccc");
 
        RadComboBox1.CheckBoxes = true;
        RadComboBox1.DataSource = dt;
        RadComboBox1.DataTextField = "Description";
        RadComboBox1.DataValueField = "ID";
        RadComboBox1.DataBind();
 
        string selecteditemlist = "1,3";
        string[] stritemId = selecteditemlist.Split(',');
 
        foreach (RadComboBoxItem item in RadComboBox1.Items)
        {
            if (stritemId.Contains(item.Value))
            {
                item.Checked = true;
            }
        }
}

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Dan
Top achievements
Rank 1
answered on 08 Nov 2011, 07:30 AM
This does not work properly if the control is rendered from inside a repeater.  I have asked one of the other people working on this project to post up an specific example to show how it is broken, and how we have created a work-around for now using a client-side script.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Nov 2011, 09:54 AM
Hello,

please submit your project using Support ticket.

Thanks,
Jayesh Goyani
Tags
ComboBox
Asked by
Dan
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Dan
Top achievements
Rank 1
Share this question
or