你可以给CheckBox一个name
能用 Request.Form["name"] != null 就选择了

解决方案 »

  1.   


    foreach(CheckBox ctl in Table2.Controls)
    {
       if(ctl.Checked)
         Response.Write(ctl.ID.ToString() "   Checked!");      
    }
      

  2.   

    cyp503(谁怕?一蓑烟雨任平生) 用你的方法出现以下错误信息:
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 指定的转换无效。这是怎么回事?
      

  3.   

    sorry应该改成
    :foreach(Control ctl in Table2.Controls)
    {
       if(ctl.GetType().ToString()=="System.Web.UI.WebControls.CheckBox")
    {
       CheckBox cb = (CheckBox)ctl;
       if(cb.Checked)
          Response.Write(ctl.ID.ToString() "   Checked!");      
         
    }
           
    }
      

  4.   

    还是不行呀.
    if(ctl.GetType().ToString()=="System.Web.UI.WebControls.CheckBox")
    我跟踪了一下,执行到这句后条件永远成立不了,好象没有找到CheckBox,我的TABLE2上有6个
    CheckBox呢,可是他只循环了两遍呀.
      

  5.   

    通过checkbox Name循环判断那的checked的值为true.
      

  6.   

    在Button2_Click中添加的控件,刷新后会消失的
      

  7.   

    通过checkbox Name循环判断那的checked的值为true.  这个具体的应该怎么写?请批教.
    ************************************
    在Button2_Click中添加的控件,刷新后会消失的
    我现在已经改成是在页面加载时添加控件,刷新后还会消失吗?我该如何做?非常感谢各位的帮助.
      

  8.   

    private void Button2_Click(object sender, System.EventArgs e)
    {
    int rowCnt;
    int rowCtr;
    int cellCtr;
    int cellCnt; rowCnt = int.Parse(TextBox1.Text);
    cellCnt = int.Parse(TextBox2.Text); for(rowCtr=1; rowCtr <= rowCnt; rowCtr++) 
    {

    TableRow tRow = new TableRow();
    Table2.Rows.Add(tRow);
    for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++) 
    {

    TableCell tCell = new TableCell();
    tRow.Cells.Add(tCell);  
    string prodID = rowCtr + "_" + cellCtr;
    CheckBox Box = new CheckBox();
    tCell.Controls.Add(Box);
    Box.Text = rowCtr + ":" + cellCtr; }
            }
       }
    private void Button1_Click(object sender, System.EventArgs e)
    {
    foreach(Control ctl in this.Table2.Controls )
    {
    TextBox1.Text= Label1.Text;
    Label1.Text=ctl.GetType().ToString();if(ctl.GetType().ToString()=="System.Web.UI.WebControls.CheckBox")
    {
    CheckBox cb = (CheckBox)ctl;
    if(cb.Checked)
    {
    Label1.Text=Label1.Text+cb.ID.ToString();
    TextBox1.Text=TextBox1.Text+cb.ID.ToString();
        }
    }     
    } }
      

  9.   

    有没有人可以帮我一下呀.
    现在用FOREACH 根本找不到CHECKBOX. 我该怎么判断用户已经选择了哪些CHECKBOX呀?
      

  10.   

    用CheckBoxList控件试试!!!-----------努力学习 不断实践 虚心讨教---------
      

  11.   

    用CheckBoxList控件试试!!!
    **********************************
    可是用CheckBoxList绑定数据库后,可以实现,一行显示三个.多行显示吗?
    我做了一个只能一行显示一个.显示多行.
      

  12.   

    给你参考一下:<%@ Page %>
    <html>
    <head>
        <script language="C#" runat="server">
          void Button1_Click(object Source, EventArgs e) {
              String s = "选择您选择了:<br>";
    //通过遍历来判断哪些选项被选中
              for (int i=0; i < Check1.Items.Count; i++) 
              {
                  if ( Check1.Items[ i ].Selected ) 
                  {
                      // 将选中的选项添加到S变量中
                      s = s + Check1.Items[i].Text;
                      s = s + "<br>";
                  }    
              }
              Label1.Text = s;
           }       void chkLayout_CheckedChanged(Object sender, EventArgs e) {
              //设置RepeatLayout属性
              if (chkLayout.Checked == true) {
                 Check1.RepeatLayout = RepeatLayout.Table;
              }
              else {
                 Check1.RepeatLayout = RepeatLayout.Flow;
              }     
           }
           
           void chkDirection_CheckedChanged(Object sender, EventArgs e) {
             //设置RepeatDirection属性
              if (chkDirection.Checked == true) {
                 Check1.RepeatDirection = RepeatDirection.Horizontal;
              }
              else {
                 Check1.RepeatDirection = RepeatDirection.Vertical;
              }  
           }
        </script></head>
    <body>
        <form runat=server>
        您喜欢的城市:
            <asp:CheckBoxList id=Check1 runat="server">
                <asp:ListItem>大连</asp:ListItem>
                <asp:ListItem>苏州</asp:ListItem>
                <asp:ListItem>昆明</asp:ListItem>
            </asp:CheckBoxList>
            <p>
            
            <asp:CheckBox id=chkLayout OnCheckedChanged="chkLayout_CheckedChanged" 
            Text="以表格的形式显示" Checked=true AutoPostBack="true" runat="server" />        <br>
            <asp:CheckBox id=chkDirection OnCheckedChanged="chkDirection_CheckedChanged" 
            Text="纵向排列" AutoPostBack="true" runat="server" />        <p>
            <asp:Button id=Button1 Text="提交" onclick="Button1_Click" runat="server"/>
            <p>
            
            <asp:Label id=Label1 font-size="10pt" runat="server"/>    </form>
    </body>
    </html>-----------努力学习 不断实践 虚心讨教---------
      

  13.   

    // Pickup input
    for ( int i = 0;i < Table3.Rows.Count ; i++ )
    {
    TableRow tabRow = Table3.Rows[i];
    for ( int j = 0;j < tabRow.Cells.Count ; j++ )
    {
    //int j = 1;
    TableCell tabCell= tabRow.Cells[j];
    if ( tabCell.Controls[k].ID.IndexOf("CheckBox_selected")>-1 )
    {
    CheckBox cbx = ( CheckBox )tabCell.Controls[k];
    int iRow = Convert.ToInt32(cbx.ID.Replace("CheckBox_selected",""));
    PickTable.Rows[iRow - 1]["selected"] = cbx.Checked.ToString();
    PickHash.Add( cbx.ID,cbx.Checked.ToString());
    break;
    }
    }
    }
      

  14.   

    TO 阿拉丁:
    if ( tabCell.Controls[j].ID.IndexOf("CheckBox_selected")>-1 )这句过不去.
    提示:
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
      

  15.   

    假设你给Checkbox设置一个ID叫做CKBOX,那么在页面里生成的代码就会是CKBOX1,CKBOX2.....你可以这样取得:Dim C As System.Collections.Specialized.NameValueCollection = Request.Form
    Dim _CK As String = Nothing
    Dim i As Integer
    For i = 0 To C.Count - 1
      If C.GetKey(i).IndexOf("CKBOX") <> -1 Then 
          _CK = _CK & "|" & C.Item(i)
      End If
    Next这样就就取得了用户所选的所有Checkbox的值了,他们以|连接在一起。
      

  16.   

    我这是从Asp转移过来的老土办法,不行不要怪我哦。哈哈。不过我这里是可以用了。
      

  17.   

    你给生成的checkbox赋个ID值,没有ID当然不能操作其ID了。