ASP.net MVC4中 @Html.DropDownList 默认值的问题
Dim i As Int32Dim tList As New List(Of SelectListItem)
Dim selItem As New SelectListItem
For i = 1 To ViewBag.UserList.Items.Count
Dim item As New SelectListItem
item.Text = ViewBag.UserList.Items(i - 1).text.ToString
item.Value = ViewBag.UserList.Items(i - 1).value.ToString
tList.Insert(i - 1, item)
If item.Text.ToUpper = ViewBag.LOG_OPTName.ToString.ToUpper Then
selItem = item
End If
Next
Dim selList As SelectList = New SelectList(tList, "Value", "Text", selItem)
这是DropDownList的所需要的SelectList,可是仍然不能实现默认值的问题。现请教各位,不在问题在哪里? --------------------编程问答-------------------- 调试下
If item.Text.ToUpper = ViewBag.LOG_OPTName.ToString.ToUpper Then
selItem = item
End If
这里有没有选中 --------------------编程问答-------------------- Refer this:
http://www.cnblogs.com/insus/p/3383277.html --------------------编程问答-------------------- Refer这个才看到效果
http://www.cnblogs.com/insus/p/3385128.html --------------------编程问答--------------------
调试看是正常选中的,但View中就是没有效果
<th style="border: 0px;">@Html.DisplayNameFor(Function(model) model.LOG_OPTName)</th>
<th style="border: 0px;">@Html.DropDownList("UserList", selList, "请选择")</th> --------------------编程问答-------------------- 持续请教各位! --------------------编程问答--------------------
--------------------编程问答--------------------
Dim i As Int32
Dim tList As New List(Of SelectListItem)
Dim selItem As string
For i = 1 To ViewBag.UserList.Items.Count
Dim item As New SelectListItem
item.Text = ViewBag.UserList.Items(i - 1).text.ToString
item.Value = ViewBag.UserList.Items(i - 1).value.ToString
tList.Insert(i - 1, item)
If item.Text.ToUpper = ViewBag.LOG_OPTName.ToString.ToUpper Then
selItem = item.value //这里。。。。
End If
Next
Dim selList As SelectList = New SelectList(tList, "Value", "Text", selItem)
List<SelectListItem> listItems = new List<SelectListItem>();
listItems.Add(new SelectListItem { Text = "1", Value = "1" });
listItems.Add(new SelectListItem { Text = "2", Value = "2", Selected = true });
listItems.Add(new SelectListItem { Text = "3", Value = "3" });
listItems.Add(new SelectListItem { Text = "4", Value = "4" });
listItems.Add(new SelectListItem { Text = "5", Value = "5" });
listItems.Add(new SelectListItem { Text = "6", Value = "6" });
ViewBag.List = listItems;
@Html.DropDownList("ddlList",ViewBag.List as IList<SelectListItem>,"请选择")
或者这个样子。。。
补充:.NET技术 , ASP.NET