国产探花免费观看_亚洲丰满少妇自慰呻吟_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>



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 诸城市| 涪陵区| 耿马| 海原县| 洞头县| 浏阳市| 故城县| 彰化县| 定边县| 四平市| 若尔盖县| 石门县| 朝阳区| 桃源县| 宁阳县| 永丰县| 惠州市| 资源县| 平阴县| 青岛市| 正镶白旗| 鹤庆县| 义乌市| 筠连县| 交城县| 绵竹市| 婺源县| 稻城县| 贵南县| 扎鲁特旗| 呼图壁县| 汽车| 喀什市| 阿合奇县| 宁城县| 马尔康县| 综艺| 黄骅市| 大兴区| 贡嘎县| 扎鲁特旗|