assign value to RadComboBox from database

1 posts, 0 answers
  1. Hadoop
    Hadoop avatar
    8 posts
    Member since:
    Jun 2015

    Posted 25 Jun 2015 Link to this post

    I am using a form to insert data as well as to edit the data. Insertion of data is fine using telerik controls. But when I try to edit the data, 
    retrieving values from the database, I am facing problem, with RadComboBox.

    My form sample is ::

    <table>
        <tr>
            <td>Date of Birth : </td>
            <td>
                <telerik:RadDatePicker ID="dtp_DOB" runat="server"></telerik:RadDatePicker>
            </td>
        </tr>
         
        <tr>
            <td>Province : </td>
            <td>
                <telerik:RadComboBox ID="rcb_province" runat="server" Sort="Ascending" AutoPostBack="true" EmptyMessage="---SELECT---"></telerik:RadComboBox>          
            </td>
        </tr>
    </table>

    my code behind logic ::

    DataTable dt = GetPersonalDetails(p_id);
     
        if (dt != null && dt.Rows.Count > 0)
        {
            DataRow dr = dt.Rows[0];       
            string province_ = dr["province"].ToString();
             
            if (rcb_province.FindItemByValue(province_) != null)
            {
                rcb_province.FindItemByValue(dr["province"].ToString()).Selected = true;
            }
        }

    Here I can get value in province_ from database but also if block is not executed. 

    I also tried ::

    if (rcb_province.FindItemByValue(dr["province"].ToString()) != null)
            {
                rcb_province.FindItemByValue(dr["province"].ToString()).Selected = true;
            }

    it is also not working.

    So how to set value from database to RadComboBox.

    When I do,

    rcb_province.Text = dr["province"].ToString();

    the value is shown in the rcb_province but there is no other items in the combo box.

    Please tell how to solve this problem.

    Thanks!!!

Back to Top