我有一個checkboxlist,我想檢查它的一些項目, 項目,我想檢查存儲在數據庫中,我從數據庫中選擇它們,並在一個循環中,我寫了thees,但只選擇最後一項:((:如何檢查checkboxlist中的項目?
var selectedRoles = (from r in DataContext.Context.Core_PagesPermission
where r.PageName.Contains(pageName) select r)
.FirstOrDefault();
if(selectedRoles != null)
{
string roles = selectedRoles.Roles;
string[] role = roles.Split(',');
int countTags = role.Count();
foreach (string word in role)
{
CheckBoxList1.SelectedValue = word;
Response.Write(word + "<br/>");
countTags -= 1;
}
}
這工作:
var selectedRoles = (from r in DataContext.Context.Core_PagesPermission where r.PageName.Contains(pageName) select r)
.FirstOrDefault();
dsRoles.DataBind();
CheckBoxList1.DataBind();
if(selectedRoles != null)
{
string roles = selectedRoles.Roles;
string[] role = roles.Split(',');
foreach (string word in role)
{
try
{
CheckBoxList1.Items.FindByValue(word).Selected = true;
}
catch (Exception exp)
{
lbError.Text= exp.ToString();
}
你能不能請你的問題更精確。我是否正確的假設:你有一個顯示所有權限的複選框列表,你想檢查數據庫中的權限存儲? – 2011-12-25 17:05:49
對不起,我的純英文 – 2011-12-25 17:15:29