Blank Template Item Issue

8 posts, 0 answers
  1. Carolus
    Carolus avatar
    8 posts
    Member since:
    Apr 2009

    Posted 30 Jun 2009 Link to this post

    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 
  2. Silver
    Silver avatar
    9 posts
    Member since:
    Jul 2009

    Posted 21 Sep 2009 Link to this post

    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

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 24 Sep 2009 Link to this post

    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.
  5. Josh
    Josh  avatar
    10 posts
    Member since:
    Nov 2013

    Posted 21 Oct 2014 in reply to Yana Link to this post

    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



  6. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 24 Oct 2014 Link to this post

    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.

     
  7. Josh
    Josh  avatar
    10 posts
    Member since:
    Nov 2013

    Posted 24 Oct 2014 in reply to Hristo Valyavicharski Link to this post

    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.

  8. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 29 Oct 2014 Link to this post

    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.

     
  9. Josh
    Josh  avatar
    10 posts
    Member since:
    Nov 2013

    Posted 29 Oct 2014 in reply to Hristo Valyavicharski Link to this post

    Thank you. This example was helpful. Turns out all I was missing was the conditional databinding expression to make it display. 

    Thanks again!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017