Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何计算asp.net中选中了多少复选框?_C#_Asp.net - Fatal编程技术网

C# 如何计算asp.net中选中了多少复选框?

C# 如何计算asp.net中选中了多少复选框?,c#,asp.net,C#,Asp.net,我有3个asp.net标准复选框控件和1个文本框。我选中1和3个复选框。在文本框中,如何计算选中了多少复选框?如果我选中1,则文本框结果为1。如果我选择1,2,文本框结果是2。如果我选中所有复选框,则结果为3 如何在asp.net中执行此操作?很简单,我假设它是复选框控件,而不是复选框列表 在您的点击事件中 protected void click(object sender, EventArgs e) { int count=0; if(checkbox1.checked)

我有3个asp.net标准复选框控件和1个文本框。我选中1和3个复选框。在文本框中,如何计算选中了多少复选框?如果我选中1,则文本框结果为1。如果我选择1,2,文本框结果是2。如果我选中所有复选框,则结果为3


如何在asp.net中执行此操作?

很简单,我假设它是复选框控件,而不是复选框列表

在您的点击事件中

protected void click(object sender, EventArgs e)
{ 
    int count=0;
    if(checkbox1.checked)
    {
        count ++;
    }
    if(checkbox2.checked)
    {
        count ++;
    }
    if(checkbox3.checked)
    {
        count ++;
    }

    textbox.text = count.ToString();
}
比如:

textBox.Text = (from chkbox in Form.Controls.OfType<CheckBox>() select chkbox).Count(chked => chked.Checked).ToString();
textBox.Text=(从Form.Controls.OfType()中的chkbox选择chkbox).Count(chked=>chked.Checked).ToString();

textBox.Text=Form.Controls.OfType().Count(chked=>chked.Checked.ToString();

我们需要更多关于您尝试过的内容的信息。您为什么不使用javascript呢?根据您已经告诉我们的内容,这并不能保证您可以访问服务器。缩进非常可怕-您为什么要这样做?=)对不起,我不明白:哈哈哈,真的很有趣,我从来不在乎独立,即使是在我自己的编码中:)然后勾选:)@MayankSharma
textBox.Text=Form.Controls.OfType<CheckBox>().Count(chked=>chked.Checked).ToString();