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

Blank Template Item Issue

7 Answers 164 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Carolus
Top achievements
Rank 1
Carolus asked on 30 Jun 2009, 03:42 PM
I have a RadComboBox with a Template.
The RadComboBox is bound to a DataSource, which returns a list of Items and Pictures. I need to add a -Choose Here- to the first item in the ComboBox. I set AppendDataBoundItems to True and I get my -Choose Here-, I also get a Blank Template item in the next line down. Then my Databound items start appearing.

I have tried a few suggestions but nothing has worked. I have tried binding the item in code behind in the on Databound event etc.

 <telerik:RadComboBox ID="RCB_Items" runat="server" AccessibilityMode="True"   
                AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="User_Items_DS"   
                DataTextField="ItemName" DataValueField="ItemID" Skin="WebBlue" Visible="False"   
                Width="250px" HighlightTemplatedItems="true">  
                  
                <ItemTemplate>  
                    <span style="vertical-align: middle;text-align:left; float: left; width: 100px;">  
                    <%#DataBinder.Eval(Container.DataItem, "ItemName")%></span>  
                    <span style="vertical-align: middle; float: none;">  
                    <img alt="" border="1" height="50"   
                        src='~/images/<%#DataBinder.Eval(Container.DataItem, "ItemId")%>'   
                        width="50" /></span>  
                </ItemTemplate>  
                          </telerik:RadComboBox>  
 
Code Behind:  
Protected Sub RCB_Items_DataBound(ByVal sender As ObjectByVal e As System.EventArgs) Handles RCB_Items.DataBound  
        Dim myItem As New RadComboBoxItem  
        myItem.Text = "-Choose Here-" 
        myItem.Value = "-1" 
        cb_Items.Items.Insert(0, myItem)  
        cb_Items.Items(0).DataBind()  
    End Sub 

7 Answers, 1 is accepted

Sort by
0
Silver
Top achievements
Rank 1
answered on 21 Sep 2009, 04:32 PM
Hi

I am experiencing the exact same problem.  Did you discover a solution?

For the two items I insert they both occur as blank lines in the combobox.

    protected void rcbOrganisationEdit_DataBound(object sender, EventArgs e)
    {
        //if organisation id is not string.empty
        if (lblOrganisationId.Text != string.Empty)
        {
            ((RadComboBox)sender).Items.Insert(0, new RadComboBoxItem(string.Format(" - Edit '{0}'",lblOrganisationName.Text), "EDIT"));
        }

        ((RadComboBox)sender).Items.Insert(0, new RadComboBoxItem(" - Add New Organisation", "ADD"));
    }

                        <ItemTemplate>
                            <ul>
                                <li class="col1">
                                    <%# DataBinder.Eval(Container, "Text")%></li>
                                <li class="col2">
                                    <%# Eval("organisation_type_description")%></li>
                            </ul>
                        </ItemTemplate>

Any Ideas?

Thanks

0
Yana
Telerik team
answered on 24 Sep 2009, 01:52 PM
Hello there,

Please test this scenario with the latest version of RadComboBox.  Also you should call DataBind() method of the newly added items. Note that the item template will be applied to them as well.

The other option is to set AllowCustomText property of the combobox to true and set Text property instead of adding additional item.

Kind regards,
Yana
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
Josh
Top achievements
Rank 1
Veteran
answered on 21 Oct 2014, 05:51 PM
Can you please provide a working example?   I cannot get this to work.  I can insert the item to the 0 index of radcombobox but the option doesn't appear in the template at all. It shows just an empty line at the top. Tried everything I could think of including calling databind() on the item as you suggested.  Funny thins is I can still click and select on that empty line and OnClientSelectedIndexChanged will fire and  args.get_item().get_value() has my added value.  So why won't it display in the template?

Thanks.


<telerik:GridBoundColumn DataField="EmployeeName" FilterControlAltText="Filter EmployeeName column" HeaderText="Employee" SortExpression="EmployeeName" UniqueName="EmployeeName">
<FilterTemplate>
<telerik:RadComboBox ID="rcbEmployee" Width="250px" runat="server" DataSourceID="sqlEmployee" DataTextField="EmployeeName" DataValueField="EmployeeName" Skin="WebBlue"
SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("EmployeeName").CurrentFilterValue%>' OnClientSelectedIndexChanged="TitleIndexChanged1">

<HeaderTemplate>
<table style="width: 100%;">
<tr>
<td style="width: 25px;" align="left">
<asp:Label ID="Label13" runat="server" SkinID="smallLabel" Text="ID"></asp:Label>
</td>
<td style="width: 100px;" align="left">
<asp:Label ID="Label14" runat="server" SkinID="smallLabel" Text="Employee"></asp:Label>
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table style="width: 100%;">
<tr>
<td style="width: 25px;" align="right">
<asp:Label ID="Label16" runat="server" SkinID="smallLabelNotBold"
Text='<%# Eval("EmployeeID")%>'></asp:Label>
</td>
<td style="width: 100px;" align="left">
<asp:Label ID="Label17" runat="server" SkinID="smallLabelNotBold"
Text='<%# Eval("employeeName") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function TitleIndexChanged1(sender, args) {
var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
if (args.get_item().get_value() == 'All') {
tableView.clearFilter();   // this works when I select the empty item.

} else {
tableView.filter("EmployeeName", args.get_item().get_value(), "EqualTo");
}
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
</telerik:GridBoundColumn>


VB.NET
Protected Sub RADGRID_ItemDataBound(sender As Object, e As GridItemEventArgs)
If TypeOf e.Item Is GridFilteringItem Then
Dim RowItem As GridFilteringItem = CType(e.Item, GridFilteringItem)

Dim rcbEmployee As RadComboBox = CType(e.Item.FindControl("rcbEmployee"), RadComboBox)
Dim NewItem As New RadComboBoxItem("All", "All")
rcbEmployee.Items.Insert(0, NewItem)
'rcbEmployee.Items(0).DataBind() Doesnt do anything

End If
End Sub



​
0
Hristo Valyavicharski
Telerik team
answered on 24 Oct 2014, 03:00 PM
Hi Josh,

For some reason the combo cannot evaluate returned data items. What if you try to use this code:

<telerik:RadComboBox ID="rcbEmployee" Width="250px" runat="server" DataSourceID="sqlEmployee" DataTextField="EmployeeName" DataValueField="EmployeeName" Skin="WebBlue"
SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("EmployeeName").CurrentFilterValue%>' OnClientSelectedIndexChanged="TitleIndexChanged1">
<ItemTemplate>
<asp:Label ID="Label16" runat="server" SkinID="smallLabelNotBold"
Text='<%# Eval("EmployeeID")%>'></asp:Label>
 
<asp:Label ID="Label17" runat="server" SkinID="smallLabelNotBold"
Text='<%# Eval("employeeName") %>'></asp:Label>
 
</ItemTemplate>
</telerik:RadComboBox>

Do you see any text?

Regards,
Hristo Valyavicharski
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Josh
Top achievements
Rank 1
Veteran
answered on 24 Oct 2014, 07:13 PM
As far as I can tell the only code that changed was the removal of the <table> inside the ItemTemplate. So, I made that change, and the result is still the same.

​
0
Hristo Valyavicharski
Telerik team
answered on 29 Oct 2014, 04:49 PM
Hi Josh,

Please find the attached sample. It shows how to insert new item. Note that the item template will be empty. If you want to display something you may use conditional data binding expression. For example:

<ItemTemplate>
<ul>
    <li class="col1"><%# Container.DataItem != null ? DataBinder.Eval(Container.DataItem, "CompanyName") : DataBinder.Eval(Container, "Text") %></li>
    <li class="col2"><%# DataBinder.Eval(Container.DataItem, "City") %></li>
    <li class="col3"><%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></li>
</ul>
</ItemTemplate>
<Items>
   <telerik:RadComboBoxItem Text="Select a country" />
</Items>

http://www.telerik.com/help/aspnet-ajax/combobox-insert-default-item-when-databinding.html
 
Regards,
Hristo Valyavicharski
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Josh
Top achievements
Rank 1
Veteran
answered on 29 Oct 2014, 07:11 PM
Thank you. This example was helpful. Turns out all I was missing was the conditional databinding expression to make it display. 

Thanks again!
Tags
ComboBox
Asked by
Carolus
Top achievements
Rank 1
Answers by
Silver
Top achievements
Rank 1
Yana
Telerik team
Josh
Top achievements
Rank 1
Veteran
Hristo Valyavicharski
Telerik team
Share this question
or