my dropdownlist HTML5
<select runat="server" id="ddlStateLegalRes" name="ddlStateLegalRes"></select>
On my page load I am binding my dropdownlist to a list collection with a list of states
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<StateList> states = ops.getStates();
ddlStateLegalRes.DataTextField = "StateRegionName";
ddlStateLegalRes.DataValueField = "StateRegionCode";
ddlStateLegalRes.DataSource = states;
ddlStateLegalRes.DataBind();
GetAllInfo();
EDITED** There is something weird going on and I cant seem to pinpoint it when I debug. For some strange reason this was working as it is supposed to but then started throwing this Error "Object Reference not set to an instance of an object"
I know the list collection is getting the correct values and I also know that "STATEOFLEGALRESIDENCE" is being returned by my stored procedure with the value "FL" and the spelling is correct.
"""Inside my GetAllInfo() method
while (sdr.Read())
{
ddlStateLegalRes.Items.FindByValue(sdr["STATEOFLEGALRESIDENCE"].ToString()).Selected = true;
}
What i suspect is that it is trying to set my dropdownlist with a value before the code is actually done binding my dropdownlist with values. So i tried to move the GetAllInfo() method into the Page_LoadComplete event and still the same error so now I am at a lost please help
Thanks