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

Adding Item to already binded Rad Multicolumn Combobox

1 Answer 142 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kavita
Top achievements
Rank 1
Kavita asked on 24 Oct 2013, 11:20 AM
Hello telerik team,

I am using rad multicolumn combo box. I am binding this combo box using vb code.
I want to add one item saying "New Contact" to it along with the other binded items.
Is it possible?

I have tried using  AppendDataBoundItems="true" property and adding RadComboboxItem through design i.e
 
<telerik:RadComboBoxItem  Text="New Contact" Value="" />

But this is adding an empty row to the combo box, and when I select the empty row, it displays "New Contact" in the combobox.

Please suggest me some solution.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Oct 2013, 10:44 AM
Hi Kavita,

Please try the following code snippet to  add a RadComboBoxItem to an already bound  RadMultiColumnComboBox.

ASPX:
<telerik:RadComboBox runat="server" ID="RadComboBox1" Height="190px" Width="420px"
    AppendDataBoundItems="true" AutoPostBack="true" NoWrap="true">
    <HeaderTemplate>
        <ul>
            <li class="col1">City Name</li>
            <li class="col2">Country Name</li>
        </ul>
    </HeaderTemplate>
    <ItemTemplate>
        <ul>
            <li class="col1">
                <%# Container.DataItem != null ? DataBinder.Eval(Container.DataItem, "Cityname") : DataBinder.Eval(Container, "Text")%>
            </li>
            <li class="col2">
                <%# Container.DataItem != null ? DataBinder.Eval(Container.DataItem, "Cityname") : DataBinder.Eval(Container, "Text")%>
            </li>
        </ul>
    </ItemTemplate>
    <Items>
        <telerik:RadComboBoxItem Text="NewItem" />
    </Items>
</telerik:RadComboBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT [Cityname], [Countryname] FROM [City]">
</asp:SqlDataSource>

CSS:
<style type="text/css">
    .multipleRowsColumns .rcbItem, .multipleRowsColumns .rcbHovered
    {
        float: left;
        margin: 0 1px;
        min-height: 13px;
        overflow: hidden;
        padding: 2px 19px 2px 6px;
        width: 125px;
    }
    .col1, .col2, .col3
    {
        margin: 0;
        padding: 0 5px 0 0;
        width: 110px;
        line-height: 14px;
        float: left;
    }
</style>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    RadComboBox1.DataBind();
    String connstring = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(connstring);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand("SELECT [Cityname], [Countryname] FROM [City]", conn);
    DataTable data = new DataTable();
    conn.Open();
    try
    {
        adapter.Fill(data);
    }
    finally
    {
        conn.Close();
    }
    RadComboBox1.DataSource = data;
    RadComboBox1.DataTextField = "Cityname";
    RadComboBox1.DataValueField = "Countryname";
    RadComboBox1.DataBind();
}

Thanks,
Princy.
Tags
General Discussions
Asked by
Kavita
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or