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 Object, ByVal 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
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
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.
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
​
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.
​
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.
Thanks again!