Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've a drop down for which I am using telerik:RadComboBox. I was using asp listbox for the drop down porpose, but for requirement I've to change the listbox drop down to telerik:RadComboBox. The drop down is working fine but the search feature selecting the value from the drop down is not working after I changed the listbox to telerik:RadComboBox.
XML
////// CountrySearch.aspx page
<tr>
<td class="tbl_label">
Country Code:
</td>
<td>
<telerik:RadComboBox ID="ddlCountryCode" runat="server" markfirstmatch="True" Rows="1"></telerik:RadComboBox>

<%--   <asp:ListBox ID="ddlCountryCode" runat="server" Rows="1"></asp:ListBox>  --%>
</td>
</tr>
<tr>
<td class="tbl_label">
Country:
</td>
<td>

<asp:TextBox ID="findCountryFilter" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search"
CausesValidation="False" />
</td>
</tr>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SearchDataSet"
TypeName="clsCountry" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCountryCode" Name="CountryCode" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="findCountryFilter" Name="searchValue" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>


HTML
////// CountrySearch.aspx page.cs
public void addCountry()
    {
        try
        {
            ddlCountryCode.Items.Clear();
            nSQLWrapper nswCountry = new nSQLWrapper();
            string strQuery = "SELECT Country_cd,Country_name  FROM Country order by Country_name";
            SqlDataReader dr = nswCountry.select(strQuery);
            //ddlCountryCode.Items.Add(new ListItem("--- SELECT ---", ""));
            ddlCountryCode.Items.Add(new RadComboBoxItem("--- SELECT ---", ""));
            if (dr.HasRows == true)
            {
                while (dr.Read())
                {
                    //ddlCountryCode.Items.Add(new ListItem(dr["Country_name"].ToString().Trim(), dr["Country_cd"].ToString().Trim()));
                    ddlCountryCode.Items.Add(new RadComboBoxItem(dr["Country_name"].ToString().Trim(), dr["Country_cd"].ToString().Trim()));
                }
            }
            dr.Close();
        }
        catch (Exception) { }
    }
/////////// clsCountry

public DataSet SearchDataSet(String CountryCode, String searchValue)
    {
        try
        {
            if (!String.IsNullOrEmpty(CountryCode))
            {
                DBObjWrapperReport nqw = new DBObjWrapperReport();
                string strQuery = "SELECT ind.industry_cd,ind.industry_name,ind.industry_address, ind.industry_output,c.Country_name," +
                "FROM industry_indanch ind " +
                "INNER JOIN country c ON c.Country_number = ind.cntry_number AND ind.bank_cd = '" + CountryCode + "'";
                
                nqw.SelectString = strQuery;
                DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                dt = nqw.GetTable();
                if (dt != null)
                {
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                    return null;
            }
            else
                return null;
        }
        catch (Exception) { return null; }
    }
}
Posted

1 solution

For the RadComboBox you need to set the ObjectDataSource Id as

DataSourceID="ObjectDataSource1"


And you have to mention the Text Field and Value Field for the RadComboBox as

VB
DataTextField="Title" DataValueField="Id"


Make the above changes and see if it works.

And also refer the Demo link below

RadComboBox ObjectDataSource[^]

If it doesn't help please feel free to comment and also paste your full code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900