开发者

Setting the first default value in a drop down list MVC

开发者 https://www.devze.com 2023-03-20 08:58 出处:网络
I want to be able to set the first value in my dropdown list as \"Select a poll\", and then load all my select items from my viewdata respectively. How would I go about doing that? My block of code ri

I want to be able to set the first value in my dropdown list as "Select a poll", and then load all my select items from my viewdata respectively. How would I go about doing that? My block of code right now looks something like this:

     <select name="ddlPolls" id="ddlPolls">
     <% foreach (var item in (string[][])ViewData["returnPolls"])                
       { %> <option value="<%= item[0] %>"><%= item[1] %></开发者_运维百科option><% } %>

     </select>

This returns a dropdown list of my polls, but I want the first value in that dropdown list to be "Select a poll" so that I can use jquery to perform .change ajax functions to load another dropdown list. Any help is much appreciated!! :D


Just write your code as follow:

 <select name="ddlPolls" id="ddlPolls">
   <option value="0">Select a poll</option>
   <% foreach (var item in (string[][])ViewData["returnPolls"])                
     { %> <option value="<%= item[0] %>"><%= item[1] %></option><% } %>

 </select>
0

精彩评论

暂无评论...
验证码 换一张
取 消