Check RadComboBox for value

3 posts, 1 answers
  1. John
    John avatar
    17 posts
    Member since:
    Apr 2013

    Posted 26 Apr 2013 Link to this post

    How and where can you check a RadComboBox for a value? I am getting an error because I am trying to set the selected value of my RCB to a value in my grid that I use databinder to get at. If the value is not in the original dataset I bound to my RCB it errors out. What I want to do is when I open my custom edit form that has this RCB in it, check to see if the value from the grid exists in the available items of the RCB. I cannot add it as it is no longer a valid option but my client keeps it for historical records. I am calling the following code in the pageLoad method but it is not working as it seems as if the RCB data items are not available here.

        myDDL.DataTextField = ds.Tables[0].Columns["DATA"].ToString();
        myDDL.DataValueField = ds.Tables[0].Columns[0].ToString();
        myDDL.DataSource = ds.Tables[0];
     
        var myValue = String.Empty;
        var ddlValue = DataBinder.Eval(DataItem, "DATA");
        Session["ddlValue"] = ddlValue;
        myValue = Session["ddlValue"].ToString();
        
        if (DataItem != null)
        {
            if (myDDL.FindItemByValue(ddlValue.ToString()) == null)
            {
                myDDL.SelectedIndex = -1;
            }
            else
            {
                myDDL.SelectedValue = ddlValue.ToString();
            }
        }
        else
        {
            myDDL.SelectedValue = myValue;
        }
    }
  2. John
    John avatar
    17 posts
    Member since:
    Apr 2013

    Posted 30 Apr 2013 Link to this post

    Yikes no one knows this?
  3. Answer
    Plamen
    Admin
    Plamen avatar
    2968 posts

    Posted 01 May 2013 Link to this post

    Hello John,

     
    If you want to use the DataItem we recommend using the ItemDataBound serve event and set the desired property of the item according to your scenario.

    Hope this will be helpful. 

    Greetings,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top