Recently I faced issue to check UN-check tree view nodes of a multilevel tree bound with SharePoint document library structure. I searched google but could not found any easy solution so decided to resolve it simply on my own. I wrote "TreeNodeCheckChanged" event. From it I called a recursive function.
function CheckChangeEvent(event) {
var obj = null;
if ((navigator.appVersion.indexOf("MSIE 7.0") > 0) || (navigator.appVersion.indexOf("MSIE 8.0") > 0)) {
obj = window.event.srcElement;
}
else {
obj = event.target;
}
if (obj == null) {
alert('Object not found!');
return false;
}
if (obj != null) {
if (obj.tagName == "INPUT" && obj.type == "checkbox") {
__doPostBack(obj.id, '');
}
return true;
}
else {
return false;
}
}
It do as post back on each click but does the trick... Hope this will help someone.
private void CheckUnCheck(TreeNodeEventArgs e)
{
if (e.Node.ChildNodes != null && e.Node.ChildNodes.Count > 0)
{
foreach (TreeNode childNode in e.Node.ChildNodes)
{
if (e.Node.Checked)
{
if (!childNode.Checked)
childNode.Checked = true;
}
else
{
if (childNode.Checked)
childNode.Checked = false;
}
if (childNode.ChildNodes != null && childNode.ChildNodes.Count > 0)
{
CheckUnCheck(new TreeNodeEventArgs(childNode));
}
}
}
}
this is not done yet. This function wont fire (I don't know why...) so I used a simple trick in Client side called a javascript function like below.{
if (e.Node.ChildNodes != null && e.Node.ChildNodes.Count > 0)
{
foreach (TreeNode childNode in e.Node.ChildNodes)
{
if (e.Node.Checked)
{
if (!childNode.Checked)
childNode.Checked = true;
}
else
{
if (childNode.Checked)
childNode.Checked = false;
}
if (childNode.ChildNodes != null && childNode.ChildNodes.Count > 0)
{
CheckUnCheck(new TreeNodeEventArgs(childNode));
}
}
}
}
function CheckChangeEvent(event) {
var obj = null;
if ((navigator.appVersion.indexOf("MSIE 7.0") > 0) || (navigator.appVersion.indexOf("MSIE 8.0") > 0)) {
obj = window.event.srcElement;
}
else {
obj = event.target;
}
if (obj == null) {
alert('Object not found!');
return false;
}
if (obj != null) {
if (obj.tagName == "INPUT" && obj.type == "checkbox") {
__doPostBack(obj.id, '');
}
return true;
}
else {
return false;
}
}
It do as post back on each click but does the trick... Hope this will help someone.
No comments:
Post a Comment