2013-08-27 144 views
0

我有一個radtreeview,由後面的代碼填充數據庫。我想要觸發一個簡單的點擊功能,但它似乎沒有工作。這可能很簡單。後面的代碼有點難看,但沒有做任何複雜的事情。這裏是我的aspx和後臺代碼:radtreeview節點不會觸發onClick事件?

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="frmMain.aspx.cs" Inherits="MCMwebapp.frmMain" %> 

<script type="text/javascript" language="javascript"> 
    function ClientNodeClicked(sender, eventArgs) { 
     var node = eventArgs.get_node(); 
     alert("You clicked " + node.get_text()); 
    } 

關閉腳本標籤沒有顯示在編輯器中由於某種原因..

< telerik:RadTreeView ID="sitesTree" runat="server" OnClientNodeClicked="ClientNodeClicked"> 
      <WebServiceSettings Path="MCMwebservice.Service1.asmx" Method="" /> 
    </telerik:RadTreeView> 

,這裏是用於填充我的樹的功能:

public void LoadSites(ref RadTreeView TreeSites, string Demogs, string Agencies, bool Config) 
    { 
     // Declare the SslConnection class variable. 
     SqlConnection sStateConn = new SqlConnection(Util.ConStrEpcrProd); 
     SqlConnection sZonesConn = new SqlConnection(Util.ConStrEpcrProd); 
     SqlConnection sAgenciesConn = new SqlConnection(Util.ConStrEpcrProd); 
     SqlCommand sStatesCmd = new SqlCommand("SELECT DISTINCT State FROM AMR_ZONE WHERE Zone_ID IN (" + Demogs + ") ORDER BY State"); 
     SqlCommand sZonesCmd = new SqlCommand(); 
     SqlCommand sAgenciesCmd = new SqlCommand(); 
     sZonesCmd.Connection = sZonesConn; 
     sAgenciesCmd.Connection = sAgenciesConn; 
     sStatesCmd.Connection = sStateConn; 
     SqlDataReader objZonesReader; 
     SqlDataReader objAgenciesReader; 
     SqlDataReader objStateReader; 

     try 
     { 
      sStateConn.Open(); 
      sZonesConn.Open(); 
      sAgenciesConn.Open(); 

      objStateReader = sStatesCmd.ExecuteReader(); 
      TreeSites.Nodes.Add(new RadTreeNode("MEDS", "MEDSRoot")); 


      while (objStateReader.Read()) 
      { 
       RadTreeNode StateNode = new RadTreeNode(objStateReader["State"].ToString()); 
       StateNode.Text = objStateReader["State"].ToString(); 

       (TreeSites.FindNodeByText("MEDS")).Nodes.Add(StateNode); 

       sZonesCmd.CommandText = "SELECT State,County,Zone_ID FROM AMR_ZONE WHERE State = '" + objStateReader["State"].ToString() + "' AND Zone_ID IN (" + Demogs + ") ORDER BY County"; 
       objZonesReader = sZonesCmd.ExecuteReader(); 

       while (objZonesReader.Read()) 
       { 
        RadTreeNode ZoneNode = new RadTreeNode(objZonesReader["County"].ToString()); 
        ZoneNode.Text = objZonesReader["Zone_ID"].ToString(); 
        bool p = ZoneNode.PostBack; 
        (TreeSites.FindNodeByText("MEDS")).Nodes[StateNode.Index].Nodes.Add(ZoneNode); 
        if (!Config) 
        { 
         // If the sites are being loaded to grant user permissions, then load the agencies as well. 
         sAgenciesCmd.CommandText = "SELECT [DESC], CODE, Demog FROM AMR_AGEN WHERE Demog = " + ZoneNode.Text + " AND CODE IN(" + Agencies + ") ORDER BY [DESC]"; 
         objAgenciesReader = sAgenciesCmd.ExecuteReader(); 

         while (objAgenciesReader.Read()) 
         { 
          RadTreeNode AgencyNode = new RadTreeNode(objAgenciesReader["DESC"].ToString()); 
          //AP 1/24/2010 changed to name the node with the CODE value 
          //AgencyNode.Name = objAgenciesReader["DESC"].ToString(); 
          AgencyNode.Text = objAgenciesReader["CODE"].ToString(); 
          AgencyNode.Value = objAgenciesReader["CODE"].ToString() + objAgenciesReader["Demog"].ToString(); 
          (TreeSites.FindNodeByText("MEDS")).Nodes[StateNode.Index].Nodes[ZoneNode.Index].Nodes.Add(AgencyNode); 
         } 

         objAgenciesReader.Close(); 
         objAgenciesReader.Dispose(); 
        } 
       } 

       objZonesReader.Close(); 
       objZonesReader.Dispose(); 
      } 

      objStateReader.Close(); 
      objStateReader.Dispose(); 

     } 
     catch (SqlException SqlEx) 
     { 
      MessageBox.Show("Database error. Please contact your administrator. LoadSite(): " 
       + SqlEx.Message, "MEDS Configuration Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("Error - LoadSite(): " 
       + ex.Message, "MEDS Configuration Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 
     } 
     finally 
     { 
      sStateConn.Close(); 
      sStateConn.Dispose(); 
      sAgenciesConn.Close(); 
      sAgenciesConn.Dispose(); 
      sZonesConn.Close(); 
      sZonesConn.Dispose(); 
      sStatesCmd.Dispose(); 
      sZonesCmd.Dispose(); 
      sAgenciesCmd.Dispose(); 
     } 
    }//  



} 

回答

0

試圖改變這一點:這個

< telerik:RadTreeView ID="sitesTree" runat="server" ... 

<telerik:RadTreeView ID="sitesTree" runat="server" ...