I have a page with user information, name, address, city, state, zip, etc. The state field is a dropdownlist populated with statecode and statename. When the page is initially linked to it accesses a database to retrieve a previously determined record and populates the fields on the page. It displays everything correctly except the state code. This is the code that populates the page:
if (usr!=null)
{
txtFirstName.Text=usr.FName;
txtLastName.Text=usr.LName;
txtAddress.Text=usr.Address;
txtCity.Text=usr.City;
string st=usr.State;
ListItem li=cboStateCode.Items.FindByValue(st);
if(li != null)
cboStateCode.SelectedIndex=cboStateCode.Items.IndexOf(li);
txtZip.Text=usr.Zip;
txtPhone.Text=usr.Phone;
txtEMail.Text=usr.EMail;
string lsContactBy=usr.ContactBy;
rblContact.SelectedValue=lsContactBy;
}
The statecode field is displaying the first item in it's list instead of the one defined by usr.state. I have traced the steps thru debug and the index is getting set to the right value.
The last field, rblContact, is a three radio button control and it is displayed correctly.
I'm puzzled!
Thanks for any suggestions.
Bill
if (usr!=null)
{
txtFirstName.Text=usr.FName;
txtLastName.Text=usr.LName;
txtAddress.Text=usr.Address;
txtCity.Text=usr.City;
string st=usr.State;
ListItem li=cboStateCode.Items.FindByValue(st);
if(li != null)
cboStateCode.SelectedIndex=cboStateCode.Items.IndexOf(li);
txtZip.Text=usr.Zip;
txtPhone.Text=usr.Phone;
txtEMail.Text=usr.EMail;
string lsContactBy=usr.ContactBy;
rblContact.SelectedValue=lsContactBy;
}
The statecode field is displaying the first item in it's list instead of the one defined by usr.state. I have traced the steps thru debug and the index is getting set to the right value.
The last field, rblContact, is a three radio button control and it is displayed correctly.
I'm puzzled!
Thanks for any suggestions.
Bill