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

[Solved] RadComboBox Q1 2009 ItemTemplate Question

3 Answers 115 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 27 Oct 2009, 04:19 PM
I am working with the ItemTemplate of the combo box and wanted to know how to add an item to the collection that didn't match the specified item template. Here's my example:

My declaration on the ASP.NET page:
<telerik:RadComboBox ID="drpObjects" runat="server" AutoPostBack="true" Skin="Vista" AllowCustomText="false" 
    DropDownWidth="350px" Height="250px">  
    <CollapseAnimation Type="InQuint" Duration="200" /> 
    <ExpandAnimation Type="OutQuint" Duration="200" /> 
    <ItemTemplate> 
        <table style="border-bottom: 1px dotted #dfdfdf; margin-bottom: 10px; font-size: 11px;" 
            width="98%">  
            <tr> 
                <td> 
                    <%#DataBinder.Eval(Container.DataItem, "LineItemID")%> 
                </td> 
                <td> 
                    <%#DataBinder.Eval(Container.DataItem, "Description")%> 
                </td> 
            </tr> 
        </table> 
    </ItemTemplate> 
</telerik:RadComboBox> 

The object is a POCO object stored in a generic list:
Namespace Entities  
    Public Class CostCenterObject  
        Inherits BaseDataEntity  
 
        Private _LineItemID As Integer = 0  
        Private _Description As String = "" 
        Private _CategoryID As Integer = 0  
        Private _ReviewOnly As Boolean 
        Private _CreateDate As DateTime  
        Private _CreateBy As String = "" 
        Private _ModifyDate As DateTime  
        Private _ModifyBy As String = "" 
        Private _Active As Boolean 
        Private _Category As String = "" 
        Private _CategoryGroupName As String = "" 
 
        Public ReadOnly Property LineItemID() As Integer 
            Get 
                Return _LineItemID  
            End Get 
        End Property 
        Public ReadOnly Property Description() As String 
            Get 
                Return _Description  
            End Get 
        End Property 
        Public ReadOnly Property CategoryID() As Integer 
            Get 
                Return _CategoryID  
            End Get 
        End Property 
        Public ReadOnly Property ReviewOnly() As Boolean 
            Get 
                Return _ReviewOnly  
            End Get 
        End Property 
        Public ReadOnly Property CreateDate() As DateTime  
            Get 
                Return _CreateDate  
            End Get 
        End Property 
        Public ReadOnly Property CreateBy() As String 
            Get 
                Return _CreateBy  
            End Get 
        End Property 
        Public ReadOnly Property ModifyDate() As DateTime  
            Get 
                Return _ModifyDate  
            End Get 
        End Property 
        Public ReadOnly Property ModifyBy() As String 
            Get 
                Return _ModifyBy  
            End Get 
        End Property 
        Public ReadOnly Property Active() As Boolean 
            Get 
                Return _Active  
            End Get 
        End Property 
        Public ReadOnly Property Category() As String 
            Get 
                Return _Category  
            End Get 
        End Property 
        Public ReadOnly Property CategoryGroupName() As String 
            Get 
                Return _CategoryGroupName  
            End Get 
        End Property 
    End Class 
    ' Instantiation code omitted...  
 
End Namespace 

And my databinding:
        Dim Objects As List(Of CostCenterObject)  
 
        Objects = _AppController.GetAvailableObjects(drpYear.SelectedValue)          
        drpObjects.DataSource = Objects  
        drpObjects.DataBind()  
 
        drpObjects.Items.Insert(0, New RadComboBoxItem("- ALL -""- ALL -")) 

However, when I select an item in the list I see the namespace of the object declaration and the item I add doesn't match the template, so it displayes as an empty table. I would prefer to use the templates idea, but is this scenario possible?

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 30 Oct 2009, 10:32 AM
Hi Chris,

You are right - the new item does not have DataItem so the template returns empty values.
Here is what you can do - change the template as follows:

<td>
     <%# Container.DataItem != null ? DataBinder.Eval(Container.DataItem, "LineItemID") : "- All -"%>
     </td>
<td>
     <%#Container.DataItem != null ? DataBinder.Eval(Container.DataItem, "Description") : "- All -"%>
     </td>

And do not forget to DataBind the new item:

drpObjects.Items.Insert(0, New RadComboBoxItem("- ALL -", "- ALL -"))
drpObjects.Items(0).DataBind()


Hope this helps.

Regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Chris
Top achievements
Rank 1
answered on 30 Oct 2009, 05:06 PM
Thanks for the reply, but is there any chance of getting the code in VB.NET format? I'm not familiar with this format in C# to be able to translate it.
0
Accepted
Chris
Top achievements
Rank 1
answered on 30 Oct 2009, 05:38 PM
Never mind, I was able to translate it!

<tr> 
    <td style="width: 75px;">  
        <%#IIf(Container.DataItem() IsNot Nothing, DataBinder.Eval(Container.DataItem, "LineItemID"), "- All - ")%> 
    </td> 
    <td> 
        <%#IIf(Container.DataItem IsNot Nothing, DataBinder.Eval(Container.DataItem, "Description"), "")%> 
    </td> 
</tr> 

Thanks, that worked perfectly!
Tags
ComboBox
Asked by
Chris
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or