服务端/客户端 访问GridView中CheckBox的方法

本文介绍了一种客户端JavaScript方法,用于在指定的GridView中查找所有的CheckBox控件,并提供了一个服务端方法来检查DataGrid中特定CheckBox的状态。

客户端访问:

 

 

function FindCheckBox()
ExpandedBlockStart.gifContractedBlock.gif
{
       
//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)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
{
          
if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0>= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif          
{
               
//write your code here
               alert("I found check box : " + Inputs[n].id);
          }

      }

}

 

服务端访问(在模板列中的CheckBox)

 

 

public object CheckValidDel() 
ExpandedBlockStart.gifContractedBlock.gif

    
int i; 
    
    
bool valid = false
    
ExpandedSubBlockStart.gifContractedSubBlock.gif    
for (i = 0; i <= dgData.Items.Count - 1; i++
        DataGridItem dgItem 
= dgData.Items(i); 
        
        CheckBox chb 
= (CheckBox)dgItem.FindControl("chk1"); 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if ((chb != null& chb.Checked) 
            
            valid 
= true
            
            
return valid; 
        }
 
        
    }
 
}

转载于:https://www.cnblogs.com/blodfox777/archive/2008/07/24/1250750.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值