SelectedValue which is invalid because it does not exist in the list of items

前端 未结 9 1725
孤独总比滥情好
孤独总比滥情好 2021-02-03 21:16

I encounter this problem repeatedly, and haven\'t a clue what is causing it. I get an exception in the DataBind: SelectedValue which is invalid because it does not exist i

9条回答
  •  借酒劲吻你
    2021-02-03 21:32

    In case you still have this problem this is how i resolved it:

    listOrgs.SelectedIndex = -1;    // Clears the SelectedIndex to avoid the exception
    listOrgs.DataSource = new Organization().DTListAll(SiteID);
    listOrgs.DataTextField = "OrganizationName"; 
    listOrgs.DataValueField = "OrganizationID"; 
    listOrgs.DataBind();            //Unless you have "listOrgs.AppendDataBoundItems = true" you don't need to clear the list
    

提交回复
热议问题