c# - conflict with dropdownlist has a SelectedValue which is invalid because it does not exist in the list of items -
i've been having problem lately specific dropdownlists in site. use following class fill of dropdownlists
public static void loadddl(string strdescription, string strvalue, datatable dtsource, dropdownlist objdropdownlist, bool blnaddselect) { objdropdownlist.datatextfield = strdescription; objdropdownlist.datavaluefield = strvalue; objdropdownlist.datasource = dtsource; objdropdownlist.databind(); if (blnaddselect) { objdropdownlist.items.insert(0, new listitem("select...", "-1")); objdropdownlist.selectedvalue = "-1"; } }
the exception thrown when databind:
'ddlaccounttypes' has selectedvalue invalid because not exist in list of items. parameter name: value description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code. exception details: system.argumentoutofrangeexception: 'ddlaccounttypes' has selectedvalue invalid because not exist in list of items. parameter name: value source error: unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using exception stack trace below. stack trace: [argumentoutofrangeexception: 'ddlaccounttypes' has selectedvalue invalid because not exist in list of items. parameter name: value] system.web.ui.webcontrols.listcontrol.performdatabinding(ienumerable datasource) +1604222 system.web.ui.webcontrols.listcontrol.ondatabinding(eventargs e) +107 system.web.ui.webcontrols.listcontrol.performselect() +34 system.web.ui.webcontrols.basedataboundcontrol.databind() +73 utilities.webutilities.loadddl(string strdescription, string strvalue, datatable dtsource, dropdownlist objdropdownlist, boolean blnaddselect) in c:\users\victor\desktop\clubcard\src\utilities\webutilities.cs:364 clubcard.administration.addclient.loadddls() +86 clubcard.administration.addclient.page_load(object sender, eventargs e) +130 system.eventhandler.invoke(object sender, eventargs e) +0 system.web.ui.control.onload(eventargs e) +99 system.web.ui.control.loadrecursive() +50 system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) +627
i believe method correct because of time works fine. there 1 specific page not working because of this. first thing comes mind, page has glitch makes enter twice method (!ispostback) whenever loads, second time enters, dropdownlist has defined data. question here is, going wrong method or there way can turn around?
regards
it inserting listitem in position 0 overwriting databound item in position 0. if selectedvalue item being overwritten error telling that selectedvalue invalid.
Comments
Post a Comment