日期:2014-05-17 浏览次数:20486 次
@if (Model.AttributeList != null && Model.AttributeList.Count > 0) { foreach (var item in Model.AttributeList) { <input type="checkbox" name="selectedAttribute" value="@item.Id" id="chk_@item.Id" @(Html.Raw(Model.SelectedAttributeList.Contains(item.Id) ? "checked=\"checked\"" : "")) /> <label for="chk_@item.Id">@item.Name</label> @: } }
------解决方案--------------------
DataTable dtcai = new DataTable();
dt = GetTable();//
cb.DataSource = dt;
cb.DataTextField = "p_name";
cb.DataValueField = "id";
cb.DataBind();
先用一个方法从数据库读取表GetTable()
如果我没理解错的话应该是要这样的方法,改得差不多了 自己看吧
------解决方案--------------------
DataTable dt = new DataTable();
------解决方案--------------------
CheckBoxList1.DataTextField = "text"; CheckBoxList1.DataValueField = "value"; CheckBoxList1.DataSource = 绑定的方法; CheckBoxList1.DataBind();