Dynamically set the option values

Posted by user281180 on Stack Overflow See other posts from Stack Overflow or by user281180
Published on 2010-03-29T12:01:01Z Indexed on 2010/03/29 12:03 UTC
Read the original article Hit count: 172

Filed under:

I have 2 different lists: EmployeeNames and Names I read the values in Names and that of EmployeeNames.

If EmployeeNames exists in Names, I must not add that value to "ToSelectBox" but to "FromSelectBox".

If EmployeeNames doesn`t exist in Names, I must add that value to "ToSelectBox" but not to "FromSelectBox".

How can I do that dynamically?

I have 2 option values as follows:

<select id="fromSelectBox" multiple="multiple" > 

  <% foreach (var item in Model.EmployeeNames) { %> 
           <option value="<%=Html.Encode(Item.Text)%>"><%=Html.Encode(item.Text)%></option>  
        <%}  
    %> 
    </select> 

select id="ToSelectBox" multiple="multiple" > 

  <% foreach (var item in Model.Names) { %> 
           <option value="<%=Html.Encode(Item.Text)%>"><%=Html.Encode(item.Text)%></option>  
        <%}  
    %> 
    </select> 

© Stack Overflow or respective owner

Related posts about mvc