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

How to add first element as "SELECT" in rad combo box

8 Answers 1294 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 24 Sep 2012, 08:15 AM
How to add first element as "SELECT" in rad combo box?
and i want to bound other database items followed by select
How can i do this plz Help.
Thanks

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Sep 2012, 09:56 AM
Hi Swapnil,

Try the following code to achieve your scenario.

C#:
protected void Page_Load(object sender, EventArgs e)
{
  SqlDataAdapter adapter = new SqlDataAdapter("SELECT EmployeeID, FirstName FROM Employees", con);
  DataTable dt = new DataTable();
  adapter.Fill(dt);
  rcb_Users.DataTextField = "FirstName";
  rcb_Users.DataValueField = "FirstName";
  rcb_Users.DataSource = dt;
  rcb_Users.DataBind();
}
protected void rcb_Users_DataBound(object sender, EventArgs e)
{
  var combo = (RadComboBox)sender;
  combo.Items.Insert(0, new RadComboBoxItem("Select", string.Empty));
}

Thanks,
Princy.
0
Swapnil
Top achievements
Rank 1
answered on 24 Sep 2012, 10:11 AM
Getting Error at the line:
var combo = (RadComboBox)sender;

Error
:
 The type or namespace name 'RadComboBoxItem' could not be found (are you missing a using directive or an assembly reference?)   

Thanks Princy.
0
Princy
Top achievements
Rank 2
answered on 25 Sep 2012, 04:25 AM
Hi Swapnil,

Please make sure that you adding the reference Telerik.Web.UI as follows.

C#:
using Telerik.Web.UI;

Thanks,
Princy.
0
Swapnil
Top achievements
Rank 1
answered on 25 Sep 2012, 04:32 AM
Yes i have that namespace as well as that dll in bin folder of project,
I have added the element "Select" by using the property   EmptyMessage="Select" and its working
just want to know is it correct?
Thanks
0
Princy
Top achievements
Rank 2
answered on 26 Sep 2012, 05:09 AM
Hi Swapnil,

You can use EmptyMessage="Select"  if you doesn't want select as the first item. And the text will go when the control get focused or any item is selected.

Hope this helps.

Thanks,
Princy.

0
Swapnil
Top achievements
Rank 1
answered on 26 Sep 2012, 05:13 AM
select remains at first position because i have added other from database using property AppendDataBoundItems="true" and works correctely,
so can i use it further or it will create any problem.
Thanks
0
Accepted
Princy
Top achievements
Rank 2
answered on 27 Sep 2012, 04:31 AM
Hi,

If you add select as an empty message you don't need to set AppendDataBoundItems="true". The empty message will be shown as text when nothing is selected in the RadCombobox. Here Select is not a RadCombobox item. But it will not create any problem. And if you need Select as a RadCombobox item you can add it as follows.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server" Width="220px" DataTextField="name" DataValueField="name" DataSourceID="SqlDataSource1" AppendDataBoundItems="true">
 <Items>
    <telerik:RadComboBoxItem Text="Select" />
 </Items>
</telerik:RadComboBox>

Hope this helps.

Thanks,
Princy.
0
Swapnil
Top achievements
Rank 1
answered on 27 Sep 2012, 04:45 AM
Thanks for the valuable reply
it helps me,
Thanks
Tags
ComboBox
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Swapnil
Top achievements
Rank 1
Share this question
or