c# - system.formatexception input string was not in a correct format when selecting a value in dropdownlist -
everytime pick value meatyqty dropdownlist in other dropdownlist, error "input string not in correct format. here code:
protected void page_load(object sender, eventargs e) { int x; (x = 0; x <= 100; x++) { listitem item = new listitem(x.tostring(),x.tostring()); tidalqty.items.add(item); meatyqty.items.add(item); darknessqty.items.add(item); macaroniqty.items.add(item); cheesyqty.items.add(item); baconqty.items.add(item); loveqty.items.add(item); } } protected void tidalqty_selectedindexchanged(object sender, eventargs e) { tidalprice.text = ((double.parse(tidalqty.selectedvalue)) * 250).tostring(); computetotal(); } protected void meatyqty_selectedindexchanged(object sender, eventargs e) { meatyprice.text = ((double.parse(meatyqty.selectedvalue)) * 500).tostring("f2"); computetotal(); } void computetotal() { double sub1 = double.parse(tidalprice.text); double sub2 = double.parse(meatyprice.text); subprice.text = (sub1+sub3).tostring("f2"); }
you're running trouble adding / rebuilding list on each post back, it's having trouble selectedvalue
.
try:
protected void page_load(object sender, eventargs e) { if (!page.ispostback) { int x; (x = 0; x <= 100; x++) { listitem item = new listitem(x.tostring(),x.tostring()); tidalqty.items.add(item); meatyqty.items.add(item); darknessqty.items.add(item); macaroniqty.items.add(item); cheesyqty.items.add(item); baconqty.items.add(item); loveqty.items.add(item); } } }
i've added call page.ispostback
.
Comments
Post a Comment