开发者

DropDownList ASp.NET MVC ALL option

When displayed the dropdownlist in asp.net mvc I have the "All" option (select All). I think a better way for the value of ALL is to give the count of the lis开发者_C百科t attached to the dropdownlist. but I am not able to do that with the following code:

myModel.CustomerDropDownList.Last().Value = customers.Count().ToString(); 
View("CustomerView",myModel); 

But it still displays the "All" value in the dropdownlist.


Since I cannot comment yet, can you please give more example of your code. You must be putting in the text "All" somewhere. All you are are doing from what I can tell is making the last item in the dropdown to be the count of how many items you have.

<select id='test' name='test'>
   <option value='a'>Customer 1</option>
   <option value='b'>Customer 2</option>
   <option value='3'>Customer 3</option>
</select>

That's how I see it.


What type is the CustomerDropDownList?

I have a funny feeling you might be trying to use a web forms drop down list?

Apologies if not.

Here's what sample list looks like for me:

 var numbers = new[] {1, 2, 3};
        IEnumerable<SelectListItem> selectItems = numbers.Select(n => new SelectListItem {Text = n.ToString(), Value = n.ToString(), Selected = true});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜