LoadOnDemand and SelectedValue

5 posts, 0 answers
  1. Hans van Rijnswoud
    Hans van Rijnswoud avatar
    72 posts
    Member since:
    Sep 2008

    Posted 15 Feb 2010 Link to this post

    Hi,

    I have in a control a ComboBox where item are load on Demand.
    When we whant to update the data i try to retreive the value with SelectedValue but off course the list is empty.
    I alreay read many item on this forum but i cannot find any solution about this!!!!

    What is the solution for this problem please?

    The code is:

     <telerik:RadComboBox runat="server" ID="ddl_ParentCustomer" Width="410px" Height="300px" 
                                    EnableLoadOnDemand="true" HighlightTemplatedItems="true" EnableVirtualScrolling="true" 
                                    OnItemsRequested="RadComboBoxCustomerOnItemsRequested" OnItemDataBound="RadComboBoxCustomerOnItemDataBound" 
                                    EmptyMessage="-Selecteer-">  
                                    <HeaderTemplate> 
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">  
                                            <tr> 
                                                <td style="width: 220px;">  
                                                    ComapanyName  
                                                </td> 
                                                <td style="width: 50px;">  
                                                    ZipCode  
                                                </td> 
                                                <td> 
                                                    City  
                                                </td> 
                                            </tr> 
                                        </table> 
                                    </HeaderTemplate> 
                                    <ItemTemplate> 
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">  
                                            <tr> 
                                                <td style="width: 220px;">  
                                                    <%# Eval("Name")%> 
                                                </td> 
                                                <td width="50px;">  
                                                    <%# Eval("ZipCode")%> 
                                                </td> 
                                                <td> 
                                                    <%# Eval("City")%> 
                                                </td> 
                                            </tr> 
                                        </table> 
                                    </ItemTemplate> 
                                </telerik:RadComboBox> 


    C# code is:
    I suppose on my method SetValues, I need to load the parent customer. But all? if I try to load all customer in the comboBox, i have a error on the method OnItemDataBound!!!!!

     protected void RadComboBoxCustomerOnItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)  
            {  
                string sFilter = e.Text;  
     
                // safety check  
                if (sFilter.Length > 100 || sFilter.IndexOf(";") != -1) return;  
     
                ddl_ParentCustomer.Items.Clear();  
     
                var customers = (from c in Customer.GetAllParentCustomers()  
                                 where c.Name.StartsWith(sFilter)  
                                 select new  
                                            {  
                                                CustomerId = c.Id,  
                                                c.Name,  
                                                c.ZipCode,  
                                                c.City  
                                            }).Page((e.NumberOfItems / 20) + 1, 20).ToList();  
     
                ddl_ParentCustomer.DataSource = customers;  
                ddl_ParentCustomer.DataBind();  
            }  
     
            protected void RadComboBoxCustomerOnItemDataBound(object sender, RadComboBoxItemEventArgs e)  
            {  
                object o = e.Item.DataItem;  
                e.Item.Text = o.GetType().GetProperty("Name").GetValue(o, null).ToString();  
                e.Item.Value = o.GetType().GetProperty("CustomerId").GetValue(o, null).ToString();  
            }  
     
    public void SetValues(Customer customer)  
    {  
     if(customer.ParentCustomerId > 0)  
    {  
      ddl_ParentCustomer.SelectedValue = customer.ParentCustomerId.ToString();  
    }  
     


    Any idee about a solution?

    Thanks,

    Edwin.

  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 18 Feb 2010 Link to this post

    Hello Edwin,

    I am not able to understand what you're trying to achieve in ItemDataBound event, could you please send us a simple runnable page demonstrating this issue? Thanks

    Best wishes,
    Yana
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 18 Feb 2010 Link to this post

    Hi Yana,
    I think i have the same problem.
    Basically, we have a combo box that is load on demand that is used to select some data in a form. This is fine when creating a new record, however, when we want to edit this record, we want the load on demand combo box to display the previously saved value. I've tried doing it by adding a manual item to the combo box, but this is not correct, as this item remains in the combo regardless of what text the user typed in.

    How can we get a load on demand combo box to start with an initial value selected?
  5. Hans van Rijnswoud
    Hans van Rijnswoud avatar
    72 posts
    Member since:
    Sep 2008

    Posted 19 Feb 2010 Link to this post

    Hello,
    Sorry for my late answer. We are very busy;-)
    I found well a solution. It's work but maybe is another way to do the same.
    It would be great if Telerik can provide a better solution for this.

    What I do is the following:
    When I want to update the page and if a record was already selected,
    I bind just this record when I build the page and it's work.
     
    if(!IsPostback) 
        if(RecordId > 0) 
        { 
           ddl_ParentCustomer.DataSource = Data.Core.Customer.GetOneParent(customer.ParentCustomerId.Value); 
                        ddl_ParentCustomer.DataBind(); 
                        ddl_ParentCustomer.SelectedValue =   customer.ParentCustomerId.ToString(); 
        } 
  6. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 19 Feb 2010 Link to this post

    Hello Edwin,

    You can also use OnDataBound event of RadComboBox  (not OnItemDataBound) to set the selected value.

    Regarding the load-on-demand combobox,  one solution of this issue is to add manually the item (as you've already done), subscribe to OnClientDropDownOpening event of the combobox and call its requestItems method in order to enable the load-on-demand mechanism.

    Best wishes,
    Yana
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017