This is a migrated thread and some comments may be shown as answers.

RadComboBox, PageLoad, AppendDataboundItems

3 Answers 91 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 23 Oct 2014, 09:38 PM
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.

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 28 Oct 2014, 01:56 PM
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.

 
0
Steven
Top achievements
Rank 1
answered on 28 Oct 2014, 07:18 PM
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")
0
Boyan Dimitrov
Telerik team
answered on 31 Oct 2014, 03:38 PM
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.

 
Tags
ComboBox
Asked by
Steven
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Steven
Top achievements
Rank 1
Share this question
or