日期:2014-05-18  浏览次数:20459 次

listview中的checkbox
在listview表头中有个checkbox,当选中时候激发事件,就向普通的checkbox不在listview表头中就会激发checkbox_change事件一样,在listview表头中的checkbox选中时候应该激发什么事件,有的说是激发itemchecked事件,但是在asp.net的webform中没有这个事件啊,前台后台怎么写,各位大哥,小弟先谢了

------解决方案--------------------
前台代码:
  
<script type="text/javascript">
var getFocus = function (elem) {
elem.select();
}

function OnTreeNodeChecked() {
var element = element = window.event.srcElement;
if (!IsCheckBox(element))
return;
var isChecked = element.checked;
var tree = TV2_GetTreeById("tvwCategory");
var node = TV2_GetNode(tree, element);
TV2_SetChildNodesCheckStatus(node, isChecked);
var parent = TV2_GetParentNode(tree, node);
TV2_NodeOnChildNodeCheckedChanged(tree, parent, isChecked);
}
//set child nodes checkbox status
function TV2_SetChildNodesCheckStatus(node, isChecked) {
var childNodes = TV2i_GetChildNodesDiv(node);
if (childNodes == null)
return;

var inputs = WebForm_GetElementsByTagName(childNodes, "INPUT");
if (inputs == null || inputs.length == 0)
return;

for (var i = 0; i < inputs.length; i++) {
if (IsCheckBox(inputs[i]))
inputs[i].checked = isChecked;
}
}

//change parent node checkbox status after child node changed
function TV2_NodeOnChildNodeCheckedChanged(tree, node, isChecked) {
if (node == null)
return;

var childNodes = TV2_GetChildNodes(tree, node);

if (childNodes == null || childNodes.length == 0)
return;

var isAllSame = true;

for (var i = 0; i < childNodes.length; i++) {
var item = childNodes[i];
var value = TV2_NodeGetChecked(item);

if (isChecked != value) {
isAllSame = false;
break;
}
}

var parent = TV2_GetParentNode(tree, node);
if (isAllSame) {
TV2_NodeSetChecked(node, isChecked);
TV2_NodeOnChildNodeCheckedChanged(tree, parent, isChecked);
}
else {
TV2_NodeSetChecked(node, false);
TV2_NodeOnChildNodeCheckedChanged(tree, parent, false);
}
}

//get node relative element(etc. checkbox)
function TV2_GetNode(tree, element) {
var id = element.id.replace(tree.id, "");
id = id.toLowerCase().replace(element.type, "");
id = tree.id + id;

var node = document.getElementById(id);
if (node == null) //leaf node, no "A" node
return element;
return node;
}

//get parent node
function TV2_GetParentNode(tree, node) {
var div = WebForm_GetParentByTagName(node, "DIV");

//The structure of node: <table>information of node</table><div>child nodes</div>
var table = div.previousSibling;
if (table == null)
return null;

return TV2i_GetNodeInElement(tree, table);
}

//get child nodes array
function TV2_GetChildNodes(tree, node) {
if (TV2_NodeIsLeaf(node))