国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET 2.0 Treeview Checkboxes - Check All - Java

2024-07-10 13:11:03
字體:
來源:轉載
供稿:網友

asp.net 2.0 treeview has many built-in features such as showing a checkbox for all the tree nodes. node level formating, style, etc., enabling the showcheckboxes="all" property sets it to show a checkbox for all the nodes. the other options are leaf, none, parent and root which show checkboxes at the respective node levels. none doesnt display checkboxes.

when we set showcheckboxes="all", we would like to provide a feature where people can select the checkbox on the root node so that all the other checkboxes are checked automatically. basically, when the parent node is checked, all the child nodes should be checked automatically.

it would be intuitive to accomplish this task at the client side without involving a postback.

the following code snippet helps in accomplishing the same.

treeview declaration

<asp:treeview id="treeview1" runat="server" datasourceid="xmldatasource1" showcheckboxes="all">

<databindings>

<asp:treenodebinding datamember="category" valuefield="id" textfield="name"></asp:treenodebinding>

<asp:treenodebinding datamember="description" valuefield="value" textfield="value"></asp:treenodebinding>

</databindings>

</asp:treeview>


in the above treeview declaration code, you can find the property event which actually is the javascript function which would accomplish this task.

the javascript code snippet is as follows:-

<script language="javascript" type="text/javascript">
function client_ontreenodechecked()
{
var obj = window.event.srcelement;
var treenodefound = false;
var checkedstate;
if (obj.tagname == "input" && obj.type == "checkbox") {
var treenode = obj;
checkedstate = treenode.checked;
do
{
obj = obj.parentelement;
} while (obj.tagname != "table")
var parenttreelevel = obj.rows[0].cells.length;
var parenttreenode = obj.rows[0].cells[0];
var tables = obj.parentelement.getelementsbytagname("table");
var numtables = tables.length
if (numtables >= 1)
{
for (i=0; i < numtables; i++)
{
if (tables[i] == obj)
{
treenodefound = true;
i++;
if (i == numtables)
{
return;
}
}
if (treenodefound == true)
{
var childtreelevel = tables[i].rows[0].cells.length;
if (childtreelevel > parenttreelevel)
{
var cell = tables[i].rows[0].cells[childtreelevel - 1];
var inputs = cell.getelementsbytagname("input");
inputs[0].checked = checkedstate;
}
else
{
return;
}
}
}
}
}
}
</script>



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 延津县| 平湖市| 合阳县| 贺州市| 安图县| 太谷县| 凤山市| 东乌珠穆沁旗| 沂水县| 台州市| 乐东| 金阳县| 雷波县| 山西省| 峨边| 大石桥市| 乌恰县| 定远县| 盐山县| 桐庐县| 南陵县| 西峡县| 神农架林区| 崇阳县| 南通市| 迁安市| 兴安县| 望江县| 屏山县| 嵊泗县| 黑水县| 新巴尔虎左旗| 宁城县| 灵宝市| 咸丰县| 万荣县| 娄底市| 资兴市| 涡阳县| 东台市| 厦门市|