EX 1:
List<ListItem> selected = chk_SEZ_Fields.Items.Cast<ListItem>()
.Where(li => li.Selected)
.ToList();
Ex 2:
List<ListItem> selected = new List<ListItem>();
foreach (ListItem item in CBLGold.Items)
if (item.Selected) selected.Add(item);
If you just want the ListItem.Value:
Ex :3
List<string> selectedValues = CBLGold.Items.Cast<ListItem>()
.Where(li => li.Selected)
.Select(li => li.Value)
.ToList();
if you want yo add to a list on buttonclick
private void btn_Click(object sender, EventArgs e)
{
for (int i = 0; i < chBoxListTables.Items.Count; i++)
{
if (chBoxListTables.GetItemChecked(i))
{
string str = (string)chBoxListTables.Items[i];
MessageBox.Show(str);
}
}
}
read the list and check the items on checkbox list on values
where Selected is the list of string with items
for (int i = 0; i < selected.Count; i++)
{
if (selected[i].ToString() == "Coega Industrial Development Zones")
CheckBoxList1.Items[0].Selected = true;
if (selected[i].ToString() == "Dube Trade Port IDZ")
CheckBoxList1.Items[1].Selected = true;
}
check if the list contains specific value
if (selected.Any(t => t.Text == "Other"))
{ TextBox1.Text = "test"; }
else
TextBox1.Text = "123";
if you want yo add to a list on buttonclick
private void btn_Click(object sender, EventArgs e)
{
for (int i = 0; i < chBoxListTables.Items.Count; i++)
{
if (chBoxListTables.GetItemChecked(i))
{
string str = (string)chBoxListTables.Items[i];
MessageBox.Show(str);
}
}
}
read the list and check the items on checkbox list on values
where Selected is the list of string with items
for (int i = 0; i < selected.Count; i++)
{
if (selected[i].ToString() == "Coega Industrial Development Zones")
CheckBoxList1.Items[0].Selected = true;
if (selected[i].ToString() == "Dube Trade Port IDZ")
CheckBoxList1.Items[1].Selected = true;
}
check if the list contains specific value
if (selected.Any(t => t.Text == "Other"))
{ TextBox1.Text = "test"; }
else
TextBox1.Text = "123";
No comments:
Post a Comment