RadComboBox, PageLoad, AppendDataboundItems

4 posts, 0 answers
  1. Steven
    Steven avatar
    2 posts
    Member since:
    Sep 2014

    Posted 23 Oct 2014 Link to this post

    Ran into a problem with the RadComboBox (rcb) today.
     
    Was setting the selected value of the rcb in the page_load function and it was working fine when the rcb looked like this.
     
                            <telerik:RadComboBox ID="rcbAssignedTo" DataSourceID="Assignees" AppendDataBoundItems="true"
                                DataTextField="Name" DataValueField="ID" runat="server" Filter="Contains">
                            </telerik:RadComboBox>
     
    Page_Load Code: rcbAssignedTo.SelectedValue = Request.QueryString("ato")
     
    However when adding an empty item and AppendDataBoundItems set to true to the list like so
     
                            <telerik:RadComboBox ID="rcbAssignedTo" DataSourceID="Assignees" AppendDataBoundItems="true"
                                DataTextField="Name" DataValueField="ID" runat="server" Filter="Contains">
                                <Items>
                                    <telerik:RadComboBoxItem Value="" />
                                </Items>
                            </telerik:RadComboBox>
     
    The Page_Load code did not work and the rcb was empty. Which is strange because at some point the rcb was populated as it was filled when opening it on the page. However simply databinding the rcb before setting the selectedvalue fixes the problem.
     
    New Page_Load Code:             rcbAssignedTo.DataBind()
                                                   rcbAssignedTo.SelectedValue = Request.QueryString("ato")

    I was just wondering if this is expected behaviour. I have seen several threads talking about LoadOnDemand being set to true will cause the rcb to populate once clicked, however it is set to false in this scenario so I don't see why the rcb would not be populated during page_load.
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 28 Oct 2014 Link to this post

    Hello,

    I would like to explain when the Page_Load is fired the RadComboBox does not have items yet. Indeed calling the DataBind will force the RadComboBox to load its items so you can use them.
    Alternative way would be to use the RadComboBox DataBound event.This event is fired when the items collection is populated and you can select an item explicitly.


    Regards,
    Boyan Dimitrov
    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Steven
    Steven avatar
    2 posts
    Member since:
    Sep 2014

    Posted 28 Oct 2014 Link to this post

    Then why does this code work in page_load without databinding it?

    <telerik:RadComboBox ID="rcbAssignedTo" DataSourceID="Assignees"
     DataTextField="Name" DataValueField="ID" runat="server" Filter="Contains">
     </telerik:RadComboBox>

    rcbAssignedTo.SelectedValue = Request.QueryString("ato")
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 31 Oct 2014 Link to this post

    Hello,

    I tested a sample scenario with RadComboBox bound to asp:SqlDataSource with/without an item in the RadComboBox markup code. In the Page_Load if I set the selected value the RadComboBox behave in same way.
    //code behind
    protected void Page_Load(object sender, EventArgs e)
        {
             rcbAssignedTo.SelectedValue = "3";
        }


    Regards,
    Boyan Dimitrov
    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.

     
Back to Top