RadComboBox selected value is empty

拜拜、爱过 提交于 2019-12-10 10:48:17

问题


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


回答1:


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.




回答2:


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"




回答3:


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



来源:https://stackoverflow.com/questions/12606197/radcombobox-selected-value-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!