This is a migrated thread and some comments may be shown as answers.
Custom Labels Combo box
2 Answers 6 Views
This is a migrated thread and some comments may be shown as answers.
Millfield
Top achievements
Rank 1
Millfield asked on 01 Jul 2014, 02:44 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 02 Jul 2014, 04:25 AM
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.
0
Millfield
Top achievements
Rank 1
answered on 02 Jul 2014, 10:14 AM
Thanks ,
This helped a lot and pointed me in the right direction

Asked by
Millfield
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Millfield
Top achievements
Rank 1
Share this question
or