Adding Item to already binded Rad Multicolumn Combobox

2 posts, 0 answers
  1. Kavita
    Kavita avatar
    39 posts
    Member since:
    Feb 2013

    Posted 24 Oct 2013 Link to this post

    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.

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Oct 2013 Link to this post

    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.
Back to Top