Mike
Mike

Reputation: 751

'ddCountries' has a SelectedValue which is invalid because it does not exist in the list of items

<asp:DropDownList runat="server" ValidationGroup="SaveInformation" ID="ddCountries">                                            
</asp:DropDownList>

Code Behind: Countries with ID and Name are coming in DataTable

ddCountries.DataSource = new  GeneralStatic().GetAllCountries();
ddCountries.DataTextField = "Name";
ddCountries.DataValueField = "ID";
ddCountries.DataBind();
ddCountries.Items.Insert(0, "-- Select Country --");

It was working fine before now throwing error

'ddCountries' has a SelectedValue which is invalid because it does not exist in the list of items.

Upvotes: 1

Views: 1090

Answers (1)

Mike
Mike

Reputation: 751

        ddCountries.Items.Clear();
        ddCountries.SelectedIndex = -1;
        ddCountries.SelectedValue = null;
        ddCountries.ClearSelection();   

Thats the solution you have to clear items value and selection before binding it ...

Upvotes: 1

Related Questions