![](/img/trans.png)
[英]How to disable certain checkbox items in checkboxlist2 if a specific list item from checkboxlist1 is checked?
[英]How to know the checkboxlist items (from dynamically) are checked or not?
我在asp.net C#中創建了2個chekboxlist,此chek box列表的列表項是從數據庫(動態地)填充的,然后我想檢查這些復選框是否被選中? 請幫我...
或者您可以使用此代碼
IEnumerable<int> allChecked = (from item in chkBoxList.Items.Cast<ListItem>()
where item.Selected
select int.Parse(item.Value));
試試這個代碼:
String values = "";
for (int i=0; i< cbl.Items.Count; i++)
{
if(cbl.Items[i].Selected)
{
values += cbl.Items[i].Value + ",";
}
}
values = values.TrimEnd(',');
或者您可以使用此代碼(Linq)
IEnumerable<int> allChecked = (from item in chkBoxList.Items.Cast<ListItem>()
where item.Selected
select int.Parse(item.Value));
嘗試這個
string ids=string.Empty;
foreach (ListItem item in checkboxlist1.Items)
{
if(item.Selected)
ids+=item.Value+",";
}
ids=ids.Trim(',');
您可以使用SelectedIndex
來檢查清單是否被選中:
if( ckl.SelectedIndex != -1 )
{
// Do Something
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.