Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RadComboBox selected value is empty

I get the SelectedValue = "" when i click on My button .

My aspx :

<telerik:RadComboBox ID="ddl_contactList" runat="server" AutoPostBack="True" CausesValidation="False"
            CollapseDelay="0" Culture="ar-EG" ExpandDelay="0" Filter="StartsWith" ItemsPerRequest="10"
            MarkFirstMatch="true" Skin="Outlook" EnableAutomaticLoadOnDemand="True" EmptyMessage="-New Menu-"
            ShowMoreResultsBox="True" OnSelectedIndexChanged="ddl_contactList_SelectedIndexChanged"
            EnableItemCaching="false" EnableLoadOnDemand="True" EnableVirtualScrolling="True">
        </telerik:RadComboBox>

My .cs :

 private void BindContactLists(int year, int main_code)
        {
            ddl_contactList.Items.Clear();
            DataTable dt = ContactList.GetContactListsByDep(year, main_code);
            ddl_contactList.DataSource = dt;
            ddl_contactList.DataTextField = "list_desc";
            ddl_contactList.DataValueField = "list_code";
            ddl_contactList.DataBind();

        }

I call it in the page load because when I call it in the !Page.Ispostback, I get the following error:

There is no assigned data source. Unable to complete callback request.

How can I fix this problem? Right now:

ddl_contactList.Text == "MySelectedItemText"

but

selectedValue == "" and selectedItem == ""

like image 804
Anyname Donotcare Avatar asked Dec 01 '25 02:12

Anyname Donotcare


2 Answers

Move your call to BindContactLists() from the Page_Load() method to the Page_Init() method. This allows the control to be setup for ViewState binding later in the page lifecycle, and allow proper population of the SelectedValue property.

like image 52
lukiffer Avatar answered Dec 02 '25 16:12

lukiffer


It's normal because you re-bind your datas => so you erase your selected value

I suggest you to set your block in !IsPostBack => you don't erase when you post

In PageLoad

if(! IsPostBack)
{

           ddl_contactList.Items.Clear();
            DataTable dt = ContactList.GetContactListsByDep(year, main_code);
            ddl_contactList.DataSource = dt;
            ddl_contactList.DataTextField = "list_desc";
            ddl_contactList.DataValueField = "list_code";
            ddl_contactList.DataBind();


}

And you persist your control with ViewState

Set EnableViewState="true"

like image 30
Aghilas Yakoub Avatar answered Dec 02 '25 16:12

Aghilas Yakoub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!