V
V. Jenks
I'm having horrible luck with events today...
I have one dropdownlist which, on changed, is supposed to
load another.
Here's my code (with needless code ommitted):
1. The ddl's
<asp:dropdownlist
id="OIItemList"
onload="OIItemList_Load"
onselectedindexchanged="OIItemList_Changed"
runat="server">
</asp:dropdownlist>
<asp:dropdownlist
id="OIProdOptionList"
runat="server">
</asp:dropdownlist>
2. The event (see above, first DDL):
protected void OIItemList_Changed(object sender,
System.EventArgs e)
{
//load product options by product ID
try
{
//get ID of selected product
int selProduct =
Convert.ToInt32(OIItemList.SelectedItem.Value);
IProduct foundProd = this.FindLocalProduct(selProduct);
//get all options from db
IList options = foundProd.Options;
if (options != null)
{
//add a default
OIProdOptionList.Items.Add(new ListItem("- Choose One
-", ""));
//add each to the dropdownlist
foreach (IProductOption po in options)
{
//capture name and price together
string name = String.Format(
"{0} {1}",
po.Name,
po.Price.ToString("C"));
//add to list
ListItem prodOp = new ListItem(name, po.ID.ToString());
//add list to control
OIProdOptionList.Items.Add(prodOp);
}
}
}
catch (Exception exp)
{
throw new ExceptionProxy(
exp.Source,
exp.GetHashCode(),
exp.Message,
exp.InnerException,
true);
}
}
I put a breakpoint in the event handler, it never happens,
so the code inside of it is irrelevant to the post, really.
Thanks!
-v
I have one dropdownlist which, on changed, is supposed to
load another.
Here's my code (with needless code ommitted):
1. The ddl's
<asp:dropdownlist
id="OIItemList"
onload="OIItemList_Load"
onselectedindexchanged="OIItemList_Changed"
runat="server">
</asp:dropdownlist>
<asp:dropdownlist
id="OIProdOptionList"
runat="server">
</asp:dropdownlist>
2. The event (see above, first DDL):
protected void OIItemList_Changed(object sender,
System.EventArgs e)
{
//load product options by product ID
try
{
//get ID of selected product
int selProduct =
Convert.ToInt32(OIItemList.SelectedItem.Value);
IProduct foundProd = this.FindLocalProduct(selProduct);
//get all options from db
IList options = foundProd.Options;
if (options != null)
{
//add a default
OIProdOptionList.Items.Add(new ListItem("- Choose One
-", ""));
//add each to the dropdownlist
foreach (IProductOption po in options)
{
//capture name and price together
string name = String.Format(
"{0} {1}",
po.Name,
po.Price.ToString("C"));
//add to list
ListItem prodOp = new ListItem(name, po.ID.ToString());
//add list to control
OIProdOptionList.Items.Add(prodOp);
}
}
}
catch (Exception exp)
{
throw new ExceptionProxy(
exp.Source,
exp.GetHashCode(),
exp.Message,
exp.InnerException,
true);
}
}
I put a breakpoint in the event handler, it never happens,
so the code inside of it is irrelevant to the post, really.
Thanks!
-v