B
Bryan Stauffer
I've got a web form with two dropdown list controls. The first one is
configured to "AutoPostBack" so that the second one can be loaded according
to whatever has been selected in the first. This would be nice to with an
asynchronous callback but I'm not there yet so this works OK. So after the
user has entered some data and clicks a "next" button I save all the data to
my Order object and save that to the Session for laster use. All of this
works. The problem is that when I come back to this page and try to get the
controls to display the data that the user selected I get the "has a
SelectedValue which is invalid because it does not exist in the list of
items" error. I've made sure the dropdown list is actually loaded with the
valid values and in fact it is! When I'm debugging everything goes smoothly
right until the browser attempts to render the page. Any ideas or
suggestions are greatly appreciated!
protected void Page_Load(object sender, EventArgs e)
{
cart = ((clsCart)Session["cart"]);
string propertyType = "Commercial";
this.SetLoanTypes(propertyType);
switch (cart.Order.PropertyType)
{
case PropertyType.Commercial:
this.drpPropertyType.SelectedValue = "Commerical";
break;
case PropertyType.Residential:
this.drpPropertyType.SelectedValue = "Residential";
break;
}
this.drpLoanType.SelectedValue = cart.Order.LoanType;
}
protected void SetLoanTypes(string PropertyType)
{
XmlDocument xml = new XmlDocument();
switch (PropertyType)
{
case "Commercial":
xml.Load(MapPath(@"~\data\commercial_loan_types.xml"));
break;
case "Residential":
xml.Load(MapPath(@"~\data\residential_loan_types.xml"));
break;
default:
throw new Exception("Invalid PropertyType in SetLoanTypes()");
}
XmlNodeList nlLoanTypes = xml.SelectNodes("loan_types/loan_type");
this.drpLoanType.Items.Clear();
foreach (XmlNode n in nlLoanTypes)
{
this.drpLoanType.Items.Add(new
ListItem(n.Attributes["display_member"].Value,
n.Attributes["value_member"].Value));
}
}
configured to "AutoPostBack" so that the second one can be loaded according
to whatever has been selected in the first. This would be nice to with an
asynchronous callback but I'm not there yet so this works OK. So after the
user has entered some data and clicks a "next" button I save all the data to
my Order object and save that to the Session for laster use. All of this
works. The problem is that when I come back to this page and try to get the
controls to display the data that the user selected I get the "has a
SelectedValue which is invalid because it does not exist in the list of
items" error. I've made sure the dropdown list is actually loaded with the
valid values and in fact it is! When I'm debugging everything goes smoothly
right until the browser attempts to render the page. Any ideas or
suggestions are greatly appreciated!
protected void Page_Load(object sender, EventArgs e)
{
cart = ((clsCart)Session["cart"]);
string propertyType = "Commercial";
this.SetLoanTypes(propertyType);
switch (cart.Order.PropertyType)
{
case PropertyType.Commercial:
this.drpPropertyType.SelectedValue = "Commerical";
break;
case PropertyType.Residential:
this.drpPropertyType.SelectedValue = "Residential";
break;
}
this.drpLoanType.SelectedValue = cart.Order.LoanType;
}
protected void SetLoanTypes(string PropertyType)
{
XmlDocument xml = new XmlDocument();
switch (PropertyType)
{
case "Commercial":
xml.Load(MapPath(@"~\data\commercial_loan_types.xml"));
break;
case "Residential":
xml.Load(MapPath(@"~\data\residential_loan_types.xml"));
break;
default:
throw new Exception("Invalid PropertyType in SetLoanTypes()");
}
XmlNodeList nlLoanTypes = xml.SelectNodes("loan_types/loan_type");
this.drpLoanType.Items.Clear();
foreach (XmlNode n in nlLoanTypes)
{
this.drpLoanType.Items.Add(new
ListItem(n.Attributes["display_member"].Value,
n.Attributes["value_member"].Value));
}
}