jquery - How to reset dropdown to zero index in MVC? -
in mvc project bind dropdown below in div
@{ list<selectlistitem> lsqty = new list<selectlistitem>(); (int = 1; <= 10; i++) { selectlistitem sl = new selectlistitem { text = i.tostring(), value = i.tostring(), selected = false }; lsqty.add(sl); } } qty: @html.dropdownlist("ddlqty", lsqty, new { style = "width:30px", @class = "positive-integer" }) that html list below
<select style="width:30px" name="ddlqty" id="ddlqty" class="positive-integer"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> on buttom functinality, want reset dropdown 0 index, how can that?
i think want values start 0 value have change loop bit , rest think can jsfiddle link change selected index
logic
@{ list<selectlistitem> lsqty = new list<selectlistitem>(); (int = 0; <= 10; i++) // starting loop 0 ******* { selectlistitem sl = new selectlistitem { text = i.tostring(), value = i.tostring(), selected = false }; lsqty.add(sl); } } qty: @html.dropdownlist("ddlqty", lsqty, new { style = "width:50px", @class = "positive-integer" }) and output should be
<select style="width:50px" name="ddlqty" id="ddlqty" class="positive-integer"> <option value="0">0</option> //new option value 0 <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> and javascript selected index be
document.getelementbyid("ddlqty").selectedindex = 0; ps: since building asp.net mvc application <%#mydropdownlist.clientid%> syntax not applicable, instead directly use id have in logic section.
@html.dropdownlist("ddlqty"... <--- id
Comments
Post a Comment