0

Anyone have a link to a code sample or can you provide a snippet to accomplish this task. I'm coming up blank on the Telerik site

2
  • 1
    Google
    – Damith
    Nov 9, 2011 at 15:05
  • thanks UnhandledException. I know what google is and how to use it. I also know how to leverage and multitask. Thanks for your input.
    – Tim
    Nov 9, 2011 at 15:27

2 Answers 2

2

I had to put something together a while ago and found snippets of code scattered throughout Telerik's site and blogs. So, I don't want to take "credit" for creating the below code... but here's what I'm using:

Add this to your css

.rcbHeader ul, .rcbFooter ul, .rcbItem ul, .rcbHovered ul, .rcbDisabled ul
{
    width: 100%;
    display: inline-block;
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.col1, .col2, .col3
{
    float: left;
    width: 100px;
    margin: 0;
    padding: 0 0px 0 0;
    line-height: 14px;
}

If you want an "item counter" add this javascript function

function UpdateItemCountField(sender, args) {
        //set the footer text
        sender.get_dropDownElement().lastChild.innerHTML = "A total of " + sender.get_items().get_count() + " items";
    }

Here's the code for the RadComboBox

<telerik:RadComboBox runat="server" ID="rcbInvoiceNumber" Height="190px" Width="350px"
    MarkFirstMatch="true" EnableLoadOnDemand="true" HighlightTemplatedItems="true"
    OnClientItemsRequested="UpdateItemCountField" OnItemDataBound="rcbInvoiceNumber_ItemDataBound"
    OnItemsRequested="rcbInvoiceNumber_ItemsRequested" EmptyMessage="Enter Invoice Number"
    ChangeTextOnKeyBoardNavigation="true" ValidationGroup="QuickPay">
    <HeaderTemplate>
        <ul>
            <li class="col1">Invoice Number</li>
            <li class="col2">PO Number</li>
            <li class="col3">Invoice Total</li>
        </ul>
    </HeaderTemplate>
    <ItemTemplate>
        <ul>
            <li class="col1">
                <%# DataBinder.Eval(Container.DataItem, "InvoiceNumber") %></li>
            <li class="col2">
                <%# DataBinder.Eval(Container.DataItem, "PONumber")%></li>
            <li class="col3">
                <%# DataBinder.Eval(Container.DataItem, "TotalInvoice", "{0:C}")%></li>
        </ul>
    </ItemTemplate>
    <FooterTemplate>
        A total of
        <asp:Literal runat="server" ID="RadComboItemsCount" />
        items
    </FooterTemplate>
</telerik:RadComboBox>

Finally, the code behind

    protected void rcbInvoiceNumber_DataBound(object sender, EventArgs e)
    {
        //set the initial footer label
        ((Literal)rcbInvoiceNumber.Footer.FindControl("RadComboItemsCount")).Text = Convert.ToString(rcbInvoiceNumber.Items.Count);
    }

    protected void rcbInvoiceNumber_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        var invs = new VInvoicesCasesTotalCollection()
            .Load();

        rcbInvoiceNumber.DataSource = invs.ToDataTable();
        rcbInvoiceNumber.DataBind();
    }

    protected void rcbInvoiceNumber_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
    {
        //set the Text and Value property of every item
        //here you can set any other properties like Enabled, ToolTip, Visible, etc.
        e.Item.Text = ((DataRowView)e.Item.DataItem)["InvoiceNumber"].ToString();
        e.Item.Value = ((DataRowView)e.Item.DataItem)["InvoiceID"].ToString();
    }

It should be noted that I've added Telerik.Web.UI to my using statements.

Hopefully this at least helps steer you in the right direction.

3
  • Thanks, this is similar to the link I put in the other post as a comment. I am doing all of it in the code behind like that example but I can't seen to get it to work properly with 'load on demand' have you tried that?
    – Tim
    Nov 9, 2011 at 19:37
  • Technically, we are using Load On Demand as when the user starts typing something in it calls OnItemsRequested. However, when I added "EnableAutomaticLoadOnDemand" to my RadComboBox I did get an error but that was corrected by adding a datasource in my Page_Init. Referencing demos.telerik.com/aspnet-ajax/combobox/examples/…
    – AJ Tatum
    Nov 9, 2011 at 20:31
  • I did look back at the telerik sample after your first post and noticed that they too were using Loas ON Demand but like you they were using a datasource on the page. I am loading entities in the code behind. I haven't given up yet. I feel that it should work.
    – Tim
    Nov 10, 2011 at 0:12
0

I've seen the links on this page and went in search of the answer on their page, becasue I was sure I had seen it before.

The link to mentioned in the comment section of clk's post is indeed a demo, but if you want the basics and quite possibly the easiest documentation to look at it would be found here.

As you mention you are loading you data on the code behind, so what you could do is load the entities first, set the data source next, and then continue to follow the rest of my linked articles code in the page load.

Hope it helps even a little.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.