Custom Labels Combo box

3 posts, 1 answers
  1. Millfield
    Millfield avatar
    3 posts
    Member since:
    Dec 2012

    Posted 01 Jul 2014 Link to this post

    Help please,
    I am using a rad combo that I am populating with a SQL data source, I have set an item template for the display which displays the correct information but when I select the item it shows the id and not the selected name, I'm not sure what I am doing wrong.

    the code I'm using is as follows

    on the aspx page

    <telerik:RadComboBox ID="DDL_Treatedby" runat="server" OnItemDataBound="DDL_Treatedby_ItemDataBound""DropDownAutoWidth="Enabled" EmptyMessage="Treated By">
    <ItemTemplate>
    <asp:Label ID="LAB_TreatedName" runat="server"></asp:Label>
    </ItemTemplate>
     </telerik:RadComboBox>

     
    and the code behind is attached to the OnItemDataBound Event

     
    protected void DDL_Treatedby_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
           { UserPermissions tempper = (UserPermissions)e.Item.DataItem;
               Label templabel = (Label)e.Item.FindControl("LAB_TreatedName");
               if (tempper != null && templabel != null)
               {
                   users temp = users.GetUserBYID(tempper.UserID);
                   templabel.Text = temp.Forename + " " + temp.Surname;
               }
               
           }


    I end up with the list been populated with the username but when an item is selected it shows a number instead of the selected name and not sure on where I am going wrong. 


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

    Posted 01 Jul 2014 in reply to Millfield Link to this post

    Hi Bridget,

    Please try the below approach to bind ItemTemplate of RadComboBox.

    ASPX:
    <telerik:RadComboBox runat="server" ID="DDL_Treatedby" EmptyMessage="select" DataSourceID="sqldsCountry" OnItemDataBound="DDL_Treatedby_ItemDataBound">
        <ItemTemplate>
            <asp:Label ID="LAB_TreatedName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CountryName") %>'></asp:Label>
        </ItemTemplate>
    </telerik:RadComboBox>

    C#:
    protected void DDL_Treatedby_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
    {
        e.Item.Text = ((DataRowView)e.Item.DataItem)["CountryName"].ToString();
        e.Item.Value = ((DataRowView)e.Item.DataItem)["CountryId"].ToString();
    }

    Let me know if you have any concern.
    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Millfield
    Millfield avatar
    3 posts
    Member since:
    Dec 2012

    Posted 02 Jul 2014 in reply to Princy Link to this post

    Thanks ,
    This helped a lot and pointed me in the right direction

Back to Top