2

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 == ""

DanM7
  • 2,203
  • 3
  • 28
  • 46
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
  • Could you provide the class for ContactList too, or at least a sample return from ContactList.GetContactListsByDep(year, main_code)? – DanM7 Sep 26 '12 at 16:58
  • Could you post more of your code here? Possible the whole load event? – Cruril Sep 27 '12 at 19:38

3 Answers3

8

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.

lukiffer
  • 11,025
  • 8
  • 46
  • 70
3

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"

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
  • I try this but i get the following error : `There is no assigned data source. Unable to complete callback request` – Anyname Donotcare Sep 27 '12 at 07:09
  • Databound controls aren't entirely stored in ViewState, and the control would not be databound when `IsPostBack` is true. – lukiffer Oct 15 '12 at 19:23
1

make sure your datasource like dataset or datatable fill when page load or init fire

soheil bijavar
  • 1,213
  • 2
  • 10
  • 18