作者:天使装着幸福 | 来源:互联网 | 2023-02-02 23:23
C#CheckBoxListSelectedItems.TexttoLabels.Text我有一个CheckBoxList和5个标签。我想将这些标签的文本值设置为用户单击按钮后从C
C#CheckBox List Selected Items.Text to Labels.Text
我有一个CheckBoxList和5个标签。
我想将这些标签的文本值设置为用户单击按钮后从CheckBoxList中选择的5个选项。 我怎么能完成这个?
提前致谢。
喜欢:
protected void button_Click(object sender, EventArgs e) { foreach (ListItem item in theCheckBoxList.Items) { item.Text = item.Selected ? "Checked" : "UnChecked"; } }
要添加您可以执行的值:
foreach (ListItem item in theCheckBoxList.Items) { item.Text = item.Selected ? item.Value : ""; }
或在迷你报告中显示al值:
string test = "you've selected :"; foreach (ListItem item in theCheckBoxList.Items) { test += item.Selected ? item.Value + ", " : ""; } labelResult.Text = test;
从Lambda Linq查找CheckboxList中的选定项目:
var x = chkList.Items.Cast().Where(i => i.Selected); if (x!=null && x.Count()>0) { List lstSelectedItems = x.ToList(); //... Other ... }
为什么你没有一个标签,点击按钮时执行以下操作:
foreach (var li in CheckList1.Items) { if(li.Checked) Label1.Text = li.Value + "
"; }
这可能不是确切的语法,而是沿着这些方向的东西。
在LINQ中使用它:
上述就是C#学习教程:C#CheckBox List Selected Items.Text to Labels.Text分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—编程笔记
foreach (var cbx3 in CheckBoxList2.Controls.OfType().Where(cbx3 => cbx3.ID == s)) { cbx3.Checked = true; }