I could not refresh treepanel(the the treenode was loaded in database)

  1. #1

    I could not refresh treepanel(the the treenode was loaded in database)

    base on the example on ext.net website for static refresh treepanel,
    I have create new treepanel with the treenodes was loaded by query in database. The firts time the treepanel was loaded successfully.the seconds, this happend an error as below:
    Webpage error details
    "
    Message: Expected identifier, string or number
    Line: 62
    Char: 21
    Code: 0
    URI: http://localhost:2970/vattu/Default.aspx
    "
    The treepanel as below. Please anybody help me ???????

    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {


    if (!IsPostBack)
    {
    //this.BuildTree(TreePanel2.Root,Convert.ToInt32(Ses sion["NhomID"].ToString()));
    this.BuildTree(TreePanel2.Root,0);
    // DataSet ds = db.GetDataSet("Nhom_Select", 0, 2);
    //LoadCboBox(CboNhom, ds);
    }

    }
    public Ext.Net.TreeNodeCollection BuildTree(Ext.Net.TreeNodeCollection nodes, int nhom_id)
    {
    if (nodes == null)
    {
    nodes = new Ext.Net.TreeNodeCollection();

    }
    Ext.Net.TreeNode root = new Ext.Net.TreeNode();
    //root.Text = "root" ;
    nodes.Add(root);
    string prefix = DateTime.Now.Second + "_";
    DataSet dsmennu = db.GetDataSet("Quyen_Nhom", 3, 0, 0, 0);
    if (dsmennu != null && dsmennu.Tables[0].Rows.Count > 0)
    {
    for (int i = 0; i < dsmennu.Tables[0].Rows.Count; i++)
    {
    Ext.Net.TreeNode node = new Ext.Net.TreeNode();
    node.Text = dsmennu.Tables[0].Rows[i]["Tenmennu"].ToString();
    node.Icon = Ext.Net.Icon.Folder;
    root.Nodes.Add(node);
    int Menu_ID = Convert.ToInt32(dsmennu.Tables[0].Rows[i][0].ToString());
    //Quyen_NguoiDung @congviec,nguoidung_id,nhom_id,menuchaid
    DataSet dsmenuchild = db.GetDataSet("Quyen_Nhom", 6, 0, nhom_id, Menu_ID);
    if (dsmenuchild != null && dsmenuchild.Tables[0].Rows.Count > 0)
    {
    for (int j = 0; j < dsmenuchild.Tables[0].Rows.Count; j++)
    {
    Ext.Net.TreeNode nodechild = new Ext.Net.TreeNode();
    nodechild.Text = dsmenuchild.Tables[0].Rows[j]["Tenmennu"].ToString();
    nodechild.Leaf = false;
    nodechild.NodeID = dsmenuchild.Tables[0].Rows[j]["Menu_ID"].ToString();
    //nodechild.Icon = Ext.Net.Icon.Film;
    nodechild.Leaf = true;
    if (dsmenuchild.Tables[0].Rows[j]["CoQuyen"].ToString().Trim().Equals("1"))

    nodechild.Checked = Ext.Net.ThreeStateBool.True;
    else
    nodechild.Checked = Ext.Net.ThreeStateBool.False;
    node.Nodes.Add(nodechild);
    }
    }
    }
    }


    return nodes;
    }

    [DirectMethod]
    public string RefreshMenu()
    {
    Ext.Net.TreeNodeCollection nodes = this.BuildTree(null,1);

    return nodes.ToJson();
    }
    </script>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head2" runat="server">
    <title>TreePanel with Checkbox Enabled Nodes - Ext.NET Examples</title>
    <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />

    <style type="text/css">
    .complete .x-tree-node-anchor span {
    text-decoration : line-through;
    color : #777;
    }
    </style>
    <script type="text/javascript">
    var getTasks = function () {
    var msg = "",
    selNodes = TreePanel2.getChecked();
    document.getElementById('nhomquyen').value="";
    Ext.each(selNodes, function(node) {
    if (msg.length > 0) {
    msg += "|";
    }
    else
    msg="";
    msg += node.id;

    document.getElementById('nhomquyen').value=msg;
    });

    };
    var refreshTree1 = function (tree) {
    var expNodes = [];
    tree.getRootNode().cascade(function(node){
    if(node.isExpanded()){
    expNodes.push(node.id);
    }
    });
    Ext.net.DirectMethods.RefreshMenu({
    success: function (result) {
    var nodes = eval(result);
    tree.initChildren(nodes);

    for(var i=0, l=expNodes.length;i++;){
    var node = tree.getNodeById(expNodes[i]);
    if(node){
    node.expand(false, false);
    }
    }

    }

    });
    }
    var refreshTree = function (tree) {
    Ext.net.DirectMethods.RefreshMenu({
    success : function (result) {
    var nodes = eval(result);
    if(nodes.length > 0){
    tree.initChildren(nodes);
    }
    else{
    tree.getRootNode().removeChildren();
    }
    }
    });
    }


    </script>
    </head>
    <body>
    <form id="Form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <asp:HiddenField ID="nhomquyen" runat="server" />
    <h1>TreePanel with Checkbox Enabled Nodes<br />
    </h1>

    <p>This example demonstrates a simple checkbox selection in a TrePanel. The Checkbox is enabled on leaf nodes by simply setting Checked="true/false" at the node level.</p>
    <ext:Store ID="storeNhom" runat="server">
    <Reader>
    <ext:JsonReader>
    <Fields>
    <ext:RecordField Name="Nhom_ID" Type="Int"></ext:RecordField>
    <ext:RecordField Name="TenNhom" Type="String"></ext:RecordField>
    </Fields>
    </ext:JsonReader>
    </Reader>
    </ext:Store>
    <ext:TreePanel
    ID="TreePanel2"
    runat="server"
    Title="My Task List"
    Icon="Accept"
    Height="400"
    Width="250"
    UseArrows="true"
    AutoScroll="true"
    Animate="true"
    EnableDD="true"
    ContainerScroll="true"
    RootVisible="false"
    HideParent="false"

    >

    <Listeners>
    <Render Handler="this.getRootNode().expand(true);" Delay="50" />
    </Listeners>
    <Tools>
    <ext:Tool Type="Refresh" Qtip="Refresh" Handler="refreshTree(#{TreePanel2});" />
    </Tools>

    <Buttons>
    <ext:Button ID="Button2" runat="server" Text="Luu" Icon="Add">
    <Listeners>
    <Click fn="getTasks" />
    </Listeners>
    <DirectEvents>
    <Click OnEvent="btnLuu_Click"></Click>
    </DirectEvents>
    </ext:Button>
    </Buttons>
    </ext:TreePanel>
    <ext:ComboBox
    runat="server"
    ID="CboNhom"
    StoreID="storeNhom"
    DisplayField="TenNhom"
    ValueField="Nhom_ID"
    EmptyText="Chọn nhóm ............."
    >
    <DirectEvents>
    <Select OnEvent="CboNhom_SelectItem"></Select>
    </DirectEvents>
    </ext:ComboBox>

    </form>
    </body>
    </html>
    Last edited by hieunk; Mar 30, 2011 at 7:35 AM. Reason: forgot some things

Similar Threads

  1. [CLOSED] How to refresh a TreeNode (attribute) in a TreePanel
    By macap in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Aug 16, 2012, 3:41 PM
  2. [CLOSED] Append a fully loaded child in a remote TreePanel
    By RCN in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: May 30, 2012, 12:23 PM
  3. How to populate treepanel with sql database
    By Fabrizio in forum 1.x Help
    Replies: 1
    Last Post: Aug 01, 2011, 9:35 AM
  4. Replies: 0
    Last Post: Sep 29, 2010, 2:29 PM
  5. Replies: 2
    Last Post: Jul 30, 2010, 12:37 AM

Posting Permissions