none
如何实现微软treeview点击树节点,仅获得树节点信息不想刷新页面? RRS feed

  • 问题

  • 想在客户端脚本实现单击TreeView中节点时执行单击事件,仅获得点击节点的树节点信息,不想刷新页面
    好像TreeView没有AutoPostBack属性,如何实现啊?
    请哪路高手帮帮忙啊?
    2009年7月31日 5:40

答案

  • 使用 AJAX 实现吧,把 TreeView 拖放到 UpdatePanel 控件中就行了
    知识改变命运,奋斗成就人生!
    2009年7月31日 6:13
    版主
  • 这样可能否不回发触发后台代码?
    treeview没有AutoPostBack属性啊
    解决
    this.tvOrganization.Attributes.Add("onclick","return getNode(event);");
    function getNode(event) {
                var v_href = event.srcElement.href;
                ....
            }
    • 已标记为答案 lxchutao 2009年8月11日 5:01
    • 已编辑 lxchutao 2009年8月11日 5:03
    2009年7月31日 10:00
  • treeview.Attributes.Add("onclick","return getNode(event);");

    在js的getNode里处理
    【孟子E章】
    2009年7月31日 14:54
    版主

全部回复

  • 使用 AJAX 实现吧,把 TreeView 拖放到 UpdatePanel 控件中就行了
    知识改变命运,奋斗成就人生!
    2009年7月31日 6:13
    版主
  • UpdatePanel 是行,但是之后的样式就丢失了,改为默认的样式了
    如果用UpdatePanel 的话,样式如何保留
    项目是用VS2008主题、内容页开发的
    • 已编辑 lxchutao 2009年7月31日 8:01
    2009年7月31日 7:57
  • 你好,你是如何设置样式的?
    知识改变命运,奋斗成就人生!
    2009年7月31日 8:00
    版主
  • 你好,UpdatePanel和样式没有直接联系啊!
    jon.valett@gmail.com
    2009年7月31日 9:11
    版主
  • 你好,通过皮肤
    2009年7月31日 9:19
  • 你好,请问能出示一下代码吗?
    jon.valett@gmail.com
    2009年7月31日 9:21
    版主
  • 不是可以把 treeview的 url 设置为  javascript:xxxxx么?

    这样link点下去  应该就可以响应客户端事件了8
    答案900, 目标五颗星 Aurvana Air, 音乐真的是随风飘来的 凉宫春日 永无止境的八月 你到底什么时候结束阿。。。。
    2009年7月31日 9:56


  • .aspx
    <%@ Page Title="" Language="C#" MasterPageFile="~/MPages/MP_Admin.Master" AutoEventWireup="true"
        CodeBehind="WebExterInterface.aspx.cs" Inherits="JYSoft.Survey.Web.AdminPages.OrgManagement.WebExterInterface" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    <%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI" TagPrefix="asp" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="CPHead" runat="server">
    <link href="../../App_Themes/blue/blue.css" rel="stylesheet" type="text/css" />
    <link href="../../App_Themes/blue/detail.css" rel="stylesheet" type="text/css" />
    <script src="../../JS/webdialog/webdialog.js" type="text/javascript"></script>
    <script src="../../JS/ChkInputs.js" type="text/javascript"></script>
    <script type="text/javascript">
    <!--
        function openFile(url) {
            window.open(url, "_blank");
        }
       
        //选择下载模板
        function selChange(xlsValue) {
            if (xlsValue != null && xlsValue != "undefined" ) {
                var tempValue = jtrim(xlsValue.value);
                if (tempValue != "") {
                    var urlFile = "../../Template/" + tempValue; //"test1.htm";
                    window.setTimeout("openFile('" + urlFile + "')",1000);
                    //document.getElementById("aTemplateFiel").href = urlFile;
                    //document.getElementById("aTemplateFiel").click();
                    return false;
                }
            }
        }
       
        //确定上传
        function CheckConfirm(fileUpload) {
            var orgid = document.getElementById("ctl00_CPContent_hidOrgId").value;
            var rootorgid = document.getElementById("ctl00_CPContent_hidRootOrgId").value;
            if (orgid == rootorgid) {
                alert("请先选择一个单位!");
                return false;
            }
            var path = document.getElementById(fileUpload).value;
            if (path == null || path == '') {
                alert('请点击“浏览...” 选择文件!');
                return false;
            }
            var postfix = path.substring(path.lastIndexOf('.') + 1, path.length).toLowerCase();
            if (postfix != 'xls' && postfix != 'xlsx') {
                alert('请选择Excel格式文件导入!');
                return false;
            }
            var d = document.getElementById("sending");
            d.style.visibility = "visible";
            return true;
        }

        //打开日志
        function openDialog1(webdialogPath) {
            var webDialogPath = document.getElementById(webdialogPath).value;
            try {
                webdialog.opendlg('导入日志', webDialogPath, 700, 400, false, true, '', true, true);
            }
            catch (e) { }
        }
    -->
    </script>
        <style type="text/css">
            .style1
            {
                font-family: "宋体";
                font-size: 12px;
                line-height: 24px;
                color: #666666;
                width: 34%;
            }
        </style>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="CPContent" runat="server">
        <table width="97%" height="465" border="0" cellpadding="0" cellspacing="0" class="table_side1">
            <tr>
                <td align="left" class="table_title_bg">
                    <span class="nav_title1">&nbsp;</span>
                    <label>
                        <input type="radio" name="RadioGroup1" checked value="Excel" />
                        <span class="gridview_title">Excel</span></label>
                    <label>
                        <input type="radio" name="RadioGroup1" value="Xml" />
                        <span class="gridview_title">Xml</span></label>
                </td>
            </tr>
            <tr>
                <td height="432" align="center" valign="top" style="padding: 15px;">
                    <table width="99%" height="356" border="0" cellpadding="0" cellspacing="1" bgcolor="#A8D3E6">
                        <tr>
                            <td height="104" align="left" bgcolor="#FFFFFF"
                                class="style1" rowspan="2" valign="top">
                                <asp:ScriptManager ID="ScriptManager1" runat="server">
                                </asp:ScriptManager>
                                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                    <ContentTemplate>
                                        <div class="treecontent">
                                            <asp:TreeView ID="tvOrganization" runat="server"
                                                onselectednodechanged="tvOrganization_SelectedNodeChanged">
                                            </asp:TreeView>
                                            <input id="hidOrgId" runat="server" type="hidden" class="hidinput"/>
                                        </div>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </td>
                            <td width="63%" height="104" align="center" bgcolor="#FFFFFF" class="gridview_font1">
                    <table width="99%" height="356" border="0" cellpadding="0" cellspacing="1" bgcolor="#A8D3E6">
                     
                      <tr>
                        <td width="63%" height="104" align="center" bgcolor="#FFFFFF" class="gridview_font1">
                        <table width="99%" height="68" border="0" cellpadding="0" cellspacing="0">
                          <tr>
                            <td width="41%" align="right" class="gridview_font1">模板下载:</td>
                            <td width="59%" align="left">
                                <asp:DropDownList ID="dropTemplateDownLoad" runat="server"
                                    onselectedindexchanged="dropTemplateDownLoad_SelectedIndexChanged"
                                    AutoPostBack="True">
                                    <asp:ListItem></asp:ListItem>
                                    <asp:ListItem Value="人员导入模板.xls">人员导入模板</asp:ListItem>
                                </asp:DropDownList>
                                </td>
                          </tr>
                          <tr>
                            <td align="right" class="gridview_font1">示例下载:</td>
                            <td align="left">
                                <asp:DropDownList ID="drpTemplateDemo" runat="server" AutoPostBack="True"
                                    onselectedindexchanged="drpTemplateDemo_SelectedIndexChanged">
                                    <asp:ListItem></asp:ListItem>
                                    <asp:ListItem Value="人员导入模板示例.xls">人员导入模板示例</asp:ListItem>
                                </asp:DropDownList>
                                </td>
                          </tr>
                        </table>
                          <br />
                          </td>
                        </tr>
                      <tr>
                        <td height="24" align="center" bgcolor="#FFFFFF" class="gridview_font1">
                        <table width="99%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td width="41%" align="right" class="gridview_font1">&nbsp;</td>
                            <td width="59%">&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="right">
                                &nbsp;&nbsp;&nbsp;&nbsp;<span class="gridview_font1">&nbsp; 上传数据:</span></td>
                            <td align="left">
                                   <asp:FileUpload ID="FileUpload1" runat="server" />
                              </td>
                          </tr>
                        </table>
                          <p><br />
                                    <asp:Button ID="btnConfirmImport" runat="server" Text="确定" OnClientClick="CheckInput();"
                                        onclick="btnConfirmImport_Click" />
                                    <asp:Button ID="btnCancel" runat="server" Text="取消" />
                         <br />
                   
                         &nbsp;</p>
                          </td>
                        </tr>
                     
                    </table>
                     
                            </td>
                            <td width="63%" height="104" align="center" bgcolor="#FFFFFF" class="gridview_font1">
                                &nbsp;</td>
                        </tr>
                        <tr>
                            <td height="24" align="center" bgcolor="#FFFFFF" class="gridview_font1">
                                 <div id="sending"
                                     style="z-index: 10; visibility: hidden; width: 377px; position: absolute; height: 92px; top: 462px; left: 650px;">
                              <table id="table6" height="80" cellspacing="2" cellpadding="0" width="400" bgcolor="#8fa8e9"
                               border="0">
                               <tr>
                                <td align="center" bgcolor="#eeeeee">正在导入数据, 请稍候...</td>
                               </tr>
                              </table>
                             </div>
                            </td>
                            <td height="24" align="center" bgcolor="#FFFFFF" class="gridview_font1">
                                &nbsp;</td>
                        </tr>
                    </table>
                    <p>
                        <br />
                    </p>
                </td>
            </tr>
        </table>
        <a id="aTemplateFiel" href="../../Template/人员导入模板.xls" target="_blank" style="display:none;">test</a>
        <input id="hidWebDialogOrgPath" runat="server" type="hidden" />
        <input id="hidRootOrgId" runat="server" type="hidden" />
    </asp:Content>

    .cs
            #region protected void tvOrganization_SelectedNodeChanged 点击组织树节点触发事件
            /// <summary>
            /// 点击组织树节点触发事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void tvOrganization_SelectedNodeChanged(object sender, EventArgs e)
            {
                string strNodeValue = this.tvOrganization.SelectedNode.Value;
                ViewState["CurrentOrgID"] = strNodeValue;
                this.hidOrgId.Value = ViewState["CurrentOrgID"].ToString();

                //if (this.tvOrganization.SelectedNode.ChildNodes != null && this.tvOrganization.SelectedNode.ChildNodes.Count < 1)
                //{
                //    //BindNextOrgBeforeClearCurrent(this.tvOrganization.SelectedNode, ViewState["CurrentOrgID"].ToString());
                //}
            }
            #endregion

    .skin
    <%--TreeView--%>
    <asp:TreeView  runat="server" ImageSet="Arrows" CssClass="treeView" ShowLines="True">
        <ParentNodeStyle Font-Bold="False" />
        <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
        <SelectedNodeStyle Font-Underline="True" HorizontalPadding="5px" VerticalPadding="0px"
            ForeColor="#5555DD" />
        <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"
            NodeSpacing="0px" VerticalPadding="0px" />
    </asp:TreeView>

    .css
    /* treeView */
    .treeView
    {
     border: 0;
    }



    谢谢

    2009年7月31日 9:58
  • 这样可能否不回发触发后台代码?
    treeview没有AutoPostBack属性啊
    解决
    this.tvOrganization.Attributes.Add("onclick","return getNode(event);");
    function getNode(event) {
                var v_href = event.srcElement.href;
                ....
            }
    • 已标记为答案 lxchutao 2009年8月11日 5:01
    • 已编辑 lxchutao 2009年8月11日 5:03
    2009年7月31日 10:00
  • 给你的建议是:学习好AJAX吧,当前很热门的技术。
    http://hi.baidu.com/2009ajun
    2009年7月31日 11:50
  • treeview.Attributes.Add("onclick","return getNode(event);");

    在js的getNode里处理
    【孟子E章】
    2009年7月31日 14:54
    版主