C
craigkenisston
Hi,
I am programming a classical registration form using asp.net.
I have the country list and a list of all states for each country in a
database.
I already have this working code in which if the user selects a country
I populate a list with the states/provinces for that country, the
dropdown for the countries is set to autopostback.
protected void Page_Load(object sender, EventArgs e)
{
Location loc = new Location();
if (!IsPostBack)
{
SqlDataReader dr = (SqlDataReader)loc.GetCountryList();
lbxCountries.DataSource = dr;
lbxCountries.DataTextField = "CTRY_NAME";
lbxCountries.DataValueField = "CTRY_CODE";
lbxCountries.DataBind();
}
SqlDataReader drst = (SqlDataReader)loc.GetStateList
(lbxCountries.SelectedItem.Value);
lbxState.DataSource = drst;
lbxState.DataTextField = "STAT_NAME";
lbxState.DataValueField = "STAT_CODE";
lbxState.DataBind();
}
However, when there's a problem in the form, for example, a missing
field, and I show the registration form again the state list is reset
to the first item in the list, i.e. it losses the position it has prior
to the attemp of registration.
So, how should I program this in order to kept the current item of the
lbxState between postbacks ?
I am programming a classical registration form using asp.net.
I have the country list and a list of all states for each country in a
database.
I already have this working code in which if the user selects a country
I populate a list with the states/provinces for that country, the
dropdown for the countries is set to autopostback.
protected void Page_Load(object sender, EventArgs e)
{
Location loc = new Location();
if (!IsPostBack)
{
SqlDataReader dr = (SqlDataReader)loc.GetCountryList();
lbxCountries.DataSource = dr;
lbxCountries.DataTextField = "CTRY_NAME";
lbxCountries.DataValueField = "CTRY_CODE";
lbxCountries.DataBind();
}
SqlDataReader drst = (SqlDataReader)loc.GetStateList
(lbxCountries.SelectedItem.Value);
lbxState.DataSource = drst;
lbxState.DataTextField = "STAT_NAME";
lbxState.DataValueField = "STAT_CODE";
lbxState.DataBind();
}
However, when there's a problem in the form, for example, a missing
field, and I show the registration form again the state list is reset
to the first item in the list, i.e. it losses the position it has prior
to the attemp of registration.
So, how should I program this in order to kept the current item of the
lbxState between postbacks ?