How to set Checked Values?

4 posts, 0 answers
  1. Dan
    Dan avatar
    139 posts
    Member since:
    Feb 2011

    Posted 03 Nov 2011 Link to this post

    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.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 04 Nov 2011 Link to this post

    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
  3. Dan
    Dan avatar
    139 posts
    Member since:
    Feb 2011

    Posted 08 Nov 2011 Link to this post

    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.
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 08 Nov 2011 Link to this post

    Hello,

    please submit your project using Support ticket.

    Thanks,
    Jayesh Goyani
Back to Top