0
對於通常的checkboxlist,我使用這些綁定是工作,但是如何動態地在gridview中爲每行綁定。如何使用後端在gridview中動態地綁定checkboxlist查詢
List<string> availableItems = new List<string> { "Item1", "Item2", "Item3", "Item4", "Item5" };
List<string> selectedItems = new List<string> { "Item1", "Item3", "Item4", "Item6" };
// add available items to checkboxlist control
foreach (string item in availableItems)
chkItems.Items.Add(new ListItem(item));
// check pre-selected items
var query = from ListItem listItem in chkItems.Items
join item in selectedItems
on listItem.Value equals item
select listItem;
foreach (ListItem listItem in query)
listItem.Selected = true;