데이터베이스의 범주가 길고 웹 페이지 공간을 저장하기 위해 CheckBoxList 컨트롤 대신 ASP.NET ListBox 컨트롤의 범주를 채 웁니다. 하지만 사용자가 여러 범주를 선택할 수 있도록 ListBox의 ListItem을 확인란으로 만들고 싶습니다. 현재 Ctrl을 눌러 여러 값을 선택하고 각 항목에을 클릭합니다. 나는 ListItem을 선택하기위한 체크 박스를 제공 할 수 있다면 사용자 친화적 일 것이라고 생각한다. 어떤 가능성이 있습니까? 이 작업을 수행 할 수목록 상자 컨트롤 ASP.NET에서 CheckBoxes로 ListItem 옵션을 사용합니다.
0
A
답변
0
방법이 당신이 같은 작업중인 모델에 부울을 추가하는 시작이다 :
public class Category
{
public int CategoryId{ get; set; }
public string CategoryName{ get; set; }
public bool selected{ get; set; } //<- we can use this for checkboxes
}
이 .cshtml이 같은 당신의 카테고리 목록과 무언가를 만들기
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<div style="height:490px; overflow:auto;">
<br />
<br />
<table class="table dim-table">
@for (int i = 0; i < Model.Categories.Count; i++)
{
@Html.HiddenFor(a => a.Categories[i].CategoryId)
<tr>
<td>
<div>
@Html.DisplayFor(model => model.Categories[i].CategoryName)
</div>
</td>
<td>
@Html.CheckBoxFor(model => model.Categories[i].selected, new { @class = "form-control" })
</td>
</tr>
}
</table>
</div>
<br />
<br />
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create and continue" class="btn btn-primary" />
</div>
</div>
</div>
</div>
}
CSS : 다음
.dim-table{
background-color: #fff;
}
.dim-table tr:nth-child(even) {
background-color: #d8f0ff;
}
.dim-table tr:nth-child(odd) {
background-color: #fff;
}
지금 당신에게 부울 세트가 카테고리를 얻을 수있는 '사실' .
희망찬 의견을 말하기 바랍니다.
+0
ASP.NET MVC를 사용할 수 없습니다. 내 코드는 ASP.NET에 있고 ListBox 컨트롤을 사용하고 있습니다. – Simant
이 ASP.Net Web Form 또는 ASP.Net MVC입니까? – Win