c# - Cannot have multiple items selected in a DropDownList Error -


im trying value of dropdownlist called ddlbrand moment selcted can use dynamically change items in dropdownlist called ddlsubbrand in same form.

this 2 drop down list in addproduct.aspx

<asp:dropdownlist id="ddlbrand" runat="server" onselectedindexchanged="ddlbrand_selectedindexchanged"  autopostback="true" ></asp:dropdownlist>  <asp:dropdownlist id="ddlsubbrand" runat="server"> </asp:dropdownlist><br /><br /> 

as code behind file, have page load bind data sql drop down list , have method selectedindexchanged i'm trying value select it.

protected void page_load(object sender, eventargs e)     {         brandmanager brandmanager = new brandmanager();         categorymanager categorymanager = new categorymanager();         if (page.ispostback == false)         {             ddlbrand.datasource = brandmanager.getallbrand();             ddlbrand.datatextfield = "brandname";             ddlbrand.datavaluefield = "brandid";             ddlbrand.databind();             listitem item = new listitem();             item.value = "0";             item.text = "--select brand--";             ddlbrand.items.insert(0, item);              ddlcategory.datasource = categorymanager.getallcategory();             ddlcategory.datatextfield = "categoryname";             ddlcategory.datavaluefield = "categoryid";             ddlcategory.databind();             listitem item1 = new listitem();             item.value = "0";             item.text = "--select category--";             ddlbrand.items.insert(0, item);           }      }     protected void ddlbrand_selectedindexchanged(object sender, eventargs args)     {         int value = int.parse(ddlbrand.selectedvalue);       } 

i seem error says :

server error in '/' application. cannot have multiple items selected in dropdownlist. description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.

exception details: system.web.httpexception: cannot have multiple items selected in dropdownlist.

source error:

an unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using exception stack trace below.

you copy pasted these lines , didn't change item item1 , ddlbrand ddlsubbrand

        item.value = "0";         item.text = "--select category--";         ddlbrand.items.insert(0, item); 

so adding item twice ddlbrand. if that's selected have 'multiple' items selected.

change code to:

        item1.value = "0";         item1.text = "--select category--";         ddlsubbrand.items.insert(0, item1); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -