我动态生成的CHECKBOX。想要在一个按钮点击事件里面获取它的ID。 
 
                            TableCell tcck = new TableCell();
                            CheckBox cb = new CheckBox();
                                
                          cb.ID = c.ToString()+k.ToString() + dsdealid.Tables[0].Rows[i]["dealid"].ToString();
                          tcck.Controls.Add(cb);
                          tr1.Cells.Add(tcck);
  然后我想要点击一个按钮。获取到我选中的ID。   

解决方案 »

  1.   

    CheckBox cb = new CheckBox();
                    cb.ID = "aaa";
    FindControl("aaa") as Checkbox
      

  2.   


       $(function(){
           $("input[type='checkbox']").click(function(){
                var cid = $(this).attr("id");         //这就是ID
           });
       });
      

  3.   

             我的ID是变量。          我要实现的功能是,选中这个CHECKBOX,就将它的ID打印出来。
      

  4.   

    动态创建控件的代码,别放在 !IsPostback里面
    你试试看
      

  5.   


    <td align="center"><span id="lbdeal0">TAB</span></td><td><input id="2008071" type="checkbox" name="2008071" /></td><td><input id="2008081" type="checkbox" name="2008081" /></td><td><input id="2008091" type="checkbox" name="2008091" /></td><td><input id="2008101" type="checkbox" name="2008101" /></td>
    一部分。
      

  6.   


      foreach (Control c in Page.Controls)
                {
                    if (c is CheckBox)
                    {
                      string i = c.ID;
                    }
                }
      

  7.   


    放Page_Load里,但是不放 !IsPostback里
      

  8.   


    就是说。。点击那个botton打印出ID?
      

  9.   

    这么多checkbox用客户端的不是更好
      

  10.   


     var inputs = document.getElementsByTagName("*"); 
     for(var i=0;i<inputs.length;i++
    {
      if(inputs[i].type=="checkbox")
       {
         if(inputs[i].checked==true)
           {
              alert(inputs[i].id);
              alert(inputs[i].name);
              alert(inputs[i].value);
            }
        }
    }