C#复选框列表中选择要Items.Text Labels.Text [英] C# CheckBox List Selected Items.Text to Labels.Text

查看:244
本文介绍了C#复选框列表中选择要Items.Text Labels.Text的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的CheckBoxList和5的标签

I have a CheckBoxList and 5 labels.

我想这些标签的文本值被设置为用户点击后,从的CheckBoxList取得的5个选项上的按钮。我将如何得到这个实现的?

I would like the text value of these Labels to be set to the 5 selections made from the CheckBoxList after the user clicks on a button. How would I get this accomplished?

感谢。

推荐答案


  • 事件绑定到一个按钮,

  • 迭代线槽项目的<$ C $财产C>的CheckBoxList

  • 选属性设置文本值>列表项

  • bind an event to a button,
  • iterate trough the Items property of the CheckBoxList
  • set the text value according to the selected property of the listitem
  • 这样的:

    protected void button_Click(object sender, EventArgs e)
    {
        foreach (ListItem item in theCheckBoxList.Items)
        {
            item.Text = item.Selected ? "Checked" : "UnChecked";
        }
    }
    



    添加一个值,你可以这样做:

    to add a value you could do:

     foreach (ListItem item in theCheckBoxList.Items)
     {
            item.Text = item.Selected ? item.Value  : "";
     }
    

    或显示在微型报告人的值:

    or display al values in a mini-report:

        string test = "you've selected :";
        foreach (ListItem item in theCheckBoxList.Items)
        {
            test += item.Selected ? item.Value + ", " : "";
        }
        labelResult.Text = test;
    

    这篇关于C#复选框列表中选择要Items.Text Labels.Text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆