如何使用C#获取所有CheckBox?

Adh*_*ham 4 c# asp.net

Asp.net.如何checkbox使用C#代码访问页面中的每个存在?

Ada*_*ley 14

这可以让你Checkbox在页面上的每一个.您可以将其更改为form1要在其中搜索的任何控件.

foreach (Control ctl in form1.Controls)
{
    if (ctl is CheckBox)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

或者,如果您知道控件的ID:

form1.FindControl("id");
Run Code Online (Sandbox Code Playgroud)