function FindCheckBox() { //Get target base & child control. var TargetBaseControl = document.getElementById('<%= GridView1.ClientID %>'); var TargetChildControl ="chkBox1"; //Get all the control of the type INPUT in the base control. var Inputs = TargetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes in side the GridView. for(var n =0; n < Inputs.length; ++n) { if(Inputs[n].type =='checkbox'&& Inputs[n].id.indexOf(TargetChildControl,0) >=0) { //write your code here alert("I found check box : "+ Inputs[n].id); } } }
服务端访问(在模板列中的CheckBox)
publicobject CheckValidDel() { int i; bool valid =false; for (i =0; i <= dgData.Items.Count -1; i++) { DataGridItem dgItem = dgData.Items(i); CheckBox chb = (CheckBox)dgItem.FindControl("chk1"); if ((chb !=null) & chb.Checked) { valid =true; return valid; } } }