<input type="checkbox" name="selAll" onclick="SelectAll(this,'DataGrid1',0);"全选/反选
注SelectAll參數說明:
DataGrid1:為DataGrid的ID
0:為checkbox在Datagrid中的列位置:從0開始,不顯示出來的列不算
function SelectAll(cur,obj,item)
{
var boolSel = false;
if(cur.checked) boolSel=true;
var objTBChildren = document.all(obj).children;
for(var i=1; i<objTBChildren.length; i++)
{
if(objTBChildren[i].tagName=="TBODY")
{
var objTRS = objTBChildren[i].children;
for(var i=0; i<objTRS.length; i++)
{
try{
var objTDS = objTRS[i].children;
var chkCtrls = objTDS[item].children;
chkCtrls[0].checked = boolSel;
}catch(e){}
}
}
}
}
private void dgMission_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemIndex -1)
{
((CheckBox)e.Item.Cells[0].FindControl("chkName")).Attributes.Add("onclick","changecolor(this)");
}
}
<script language="javascript"
function changecolor(sender)
{
var temp=sender.parentElement;
while(temp.tagName != 'TR')
{
temp=temp.parentElement;
}
if(temp!=null)
{
temp.style.backgroundColor='Green';
}
}
</script