2

我有一个最初显示树视图的 aspx 页面。当按下树上的子节点时,我希望填充页面上的 RadGrid。我设置了数据源并进行了 databind() 调用,但它似乎不起作用。我也尝试过使用 needDataSource 但它有同样的问题。这是我的代码:

namespace MCMwebapp{ public partial class frmLookupTables : System.Web.UI.Page
{ 

    int CurrentDemog;
    bool LookupDataLoaded;
    bool isOPS = false;
    string selectedNode;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }

    }



    protected void LookupsTree_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
    {

        RadTreeNode currNode = e.Node;
        if (currNode.Nodes.Count == 0) {
            if (currNode.ParentNode.Text != "Treatments" && !String.IsNullOrEmpty(currNode.Text))
            {
                selectedNode = currNode.Text;
                Session["selectedNode"] = selectedNode;
                loadLookupGrid();

            }

        }

    }


    protected void loadLookupGrid()
    {
        using (ServiceReference1.Service1SoapClient myService = new ServiceReference1.Service1SoapClient())
        {
            if (Session["selectedNode"] != null)
            {
                LookupGrid.DataSource = myService.getTable();
                LookupGrid.Databind();

            }
        }


}

}

我的aspx代码:

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

<asp:Label ID="LookupLabel" runat="server"></asp:Label>


  <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="LookupGrid">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="LookupGrid" LoadingPanelID="TablePanel"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

 <telerik:RadAjaxPanel ID="TreePanel" runat="server" HorizontalAlign="NotSet" style="background-color:#808080; float:left" Width="40%">


     <telerik:RadTreeView ID="LookupsTree" runat="server" OnClientNodeClicked="ClientNodeClicked" OnNodeClick="LookupsTree_NodeClick">

    </telerik:RadTreeView>

</telerik:RadAjaxPanel>



 <telerik:RadAjaxLoadingPanel ID="TablePanel" runat="server" HorizontalAlign="Right"
    style="background-color:#E92326; float:right" Width="40%" >


     <telerik:RadGrid ID="LookupGrid" runat="server" BackColor="Gray"
         BorderColor="#404040" BorderStyle="Solid" CellSpacing="0" GridLines="None"
         Skin="MetroTouch">

         <FilterMenu EnableImageSprites="False">
         </FilterMenu>
     </telerik:RadGrid>




 </telerik:RadAjaxLoadingPanel>
  <script type="text/javascript">

   function ClientNodeClicked(sender, eventArgs) {
       var node = eventArgs.get_node();
       node.toggle();
   }
   </script>

4

1 回答 1

1

改变:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
  <AjaxSettings>
      <telerik:AjaxSetting AjaxControlID="LookupGrid">
          <UpdatedControls>
              <telerik:AjaxUpdatedControl ControlID="LookupGrid" LoadingPanelID="TablePanel"></telerik:AjaxUpdatedControl>
          </UpdatedControls>
      </telerik:AjaxSetting>
  </AjaxSettings>

进入:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
  <AjaxSettings>
      <telerik:AjaxSetting AjaxControlID="LookupsTree">
          <UpdatedControls>
              <telerik:AjaxUpdatedControl ControlID="LookupGrid" LoadingPanelID="TablePanel"></telerik:AjaxUpdatedControl>
          </UpdatedControls>
      </telerik:AjaxSetting>         
      <telerik:AjaxSetting AjaxControlID="LookupGrid">
          <UpdatedControls>
              <telerik:AjaxUpdatedControl ControlID="LookupGrid" LoadingPanelID="TablePanel"></telerik:AjaxUpdatedControl>
          </UpdatedControls>
      </telerik:AjaxSetting>
  </AjaxSettings>

问题是您的 AJAX 已启用,并且您RadTreeView没有更新RadGridAJAX 的权限。

使用时RadAjaxManager,可以去掉包边RadAjaxPanels

另外,我认为Session不能在 Ajax PostBack 上设置,但不确定。没有必要把它放在里面Session,因为你可以将它作为参数传递给你的函数 - loadLookupGrid(selectedNode);

于 2013-09-06T19:17:21.507 回答