问题
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