tree与GridView交互

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OgGridView.aspx.cs" Inherits="LY.CCPCUEP.UI.Uep.html.OgGridView" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
     <link href="jquery.ztree/style.css" rel="stylesheet" />
    <link href="jquery.ztree/zTreeStyle.css" rel="stylesheet" />
    <script src="jquery.ztree/jquery-1.4.4.min.js"></script>
    <script src="jquery.ztree/jquery.ztree.core.js"></script>
    <script src="jOrgChart-master/jquery.min.js"></script>
    <style>
       
        .tj {
            color: #000000;
            text-align: center;
            font-weight: bold;
            font-size: 12px;
            border: 1px solid #990000;
            border-radius: 3px;
        }
        
        
       
    </style>
</head>
<body>
    <form id="form1" runat="server">
         <div>
            <table style="width:100%;height:50px; text-align:left; border-bottom : 1px solid #cac5c3;box-sizing: border-box; ">
                <tr >
                    <td class="tj" onClick="jc_click()">基层工会:<label id="jcghs"></label></td>
                    <td class="tj" onClick="hf_click()">分会:<label id="fhs"></label></td>
                    <td class="tj  onClick="hy_click()">会员:<label id="hys"></label></td>
                    <td class="tj">男:<label id="nxs"></label></td>
                    <td class="tj">女:<label id="vxs"></label></td>
                </tr>
                <tr>
                    <td class="tj">中专:<label id="zzs"></label></td>
                    <td class="tj">专科:<label id="zks"></label></td>
                    <td class="tj">本科:<label id="bks"></label></td>
                    <td class="tj">硕士研究生:<label id="shyjss"></label></td>
                    <!--<td class="tj">博士研究生:<label id="bsyjss"></label></td>-->
                    <td class="tj">其他学历:<label id="qtxls"></label></td>
                </tr>
            </table>
          
            <div id='jOrgChartTable' style="width:100%;float:left; ">
                <div>
                     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                          OnPageIndexChanging="GridView1_PageIndexChanging"
                         ondatabound="GridView1_DataBound" AllowPaging="True" PageSize="5" 
                         style="margin-left: 0px" Width="100%" CellPadding="4" ForeColor="#333333" GridLines="None"  >
                         <PagerTemplate> 
         <asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1)  + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>  
         <asp:LinkButton ID="lbnFirst" runat="Server" Text="首页"  Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="First" ></asp:LinkButton>  
        <asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="Prev"  ></asp:LinkButton>  
        <asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Next" ></asp:LinkButton>  
         <asp:LinkButton ID="lbnLast" runat="Server" Text="尾页"   Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Last" ></asp:LinkButton>  
         到第<asp:dropdownlist id="PageDropDownList"
                  autopostback="true"
                  onselectedindexchanged="PageDropDownList_SelectedIndexChanged" 
                  runat="server"/> 页  
        
                             
                             
          每页<asp:dropdownlist id="PageSizePageDropdownlist"
                  autopostback="true"
                  onselectedindexchanged="PageSizeDropdownlist_SelectedIndexChanged" 
                  runat="server"> 
              <asp:ListItem>5</asp:ListItem>
              <asp:ListItem>10</asp:ListItem>
              <asp:ListItem>20</asp:ListItem>
              <asp:ListItem>30</asp:ListItem>

            </asp:dropdownlist></PagerTemplate>
                         <AlternatingRowStyle BackColor="White" />
                        <Columns>
                            <%--<asp:BoundField DataField="UNION_CODE" HeaderText="部门ID" ReadOnly="true" Visible="true" />--%>
                            <asp:BoundField DataField="UNION_NAME" HeaderText="公会名称" />
                           <asp:BoundField DataField="PARENT_ORGANIZATION_NAME" HeaderText="上级公会名称" />
                         
                        </Columns>

                          <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                         <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                         <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                          <RowStyle HorizontalAlign ="Center" BackColor="#FFFBD6" ForeColor="#333333" />
                         <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                         <SortedAscendingCellStyle BackColor="#FDF5AC" />
                         <SortedAscendingHeaderStyle BackColor="#4D0000" />
                         <SortedDescendingCellStyle BackColor="#FCF6C0" />
                         <SortedDescendingHeaderStyle BackColor="#820000" />
                    </asp:GridView>
               
                 </div>
            </div>
        </div>
    </form>
</body>
</html>

<script type="text/javascript">
        
    $(document).ready(function () {
        
        //初始化
        Inint('<%=UNION_CODE%>');
    });
    //初始化加载组织结构图
    function Inint(code) {
        $.ajax({
            url: '../Ajax/OrganizationalStructureAjax.ashx',
            type: 'post',
            dataType: 'json',
            async: false,
            data: { 'ajaxMethod': 'Summary', 'treeNodeID': code },
            success: function (data) {

                $("#jcghs").text(data.jcghs == "" ? 0 : data.jcghs);
                $("#fhs").text(data.fhs == "" ? 0 : data.fhs);
                $("#hys").text(data.hys == "" ? 0 : data.hys);
                $("#nxs").text(data.nxs == "" ? 0 : data.nxs);
                $("#vxs").text(data.vxs == "" ? 0 : data.vxs);
                $("#zzs").text(data.zzs == "" ? 0 : data.zzs);
                $("#zks").text(data.zks == "" ? 0 : data.zks);
                $("#bks").text(data.bks == "" ? 0 : data.bks);
                $("#shyjss").text(data.shyjss == "" ? 0 : data.shyjss);
               
                $("#qtxls").text(data.qtxls == "" ? 0 : data.qtxls);
            }
        });
    };
    
</script>
using LY.CCPCUEP.BLL.UEP;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LY.CCPCUEP.UI.Uep.html
{

    
    public partial class OgGridView : System.Web.UI.Page
    {
        public string UNION_CODE
        {
            get
            {
                string s = Request.QueryString["UNION_CODE"];
                if (!string.IsNullOrEmpty(s))
                {
                    return s;
                }
                else
                {
                    return "234E45F0077881AAE0430AA3034681AA";
                }
               
            }

        }


        DataTable dt = new DataTable();
        T_UEP_DB_ZTREEBLL dll = new T_UEP_DB_ZTREEBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!IsPostBack)
            {
               
                bind();
            }
        }
        //绑定
        public void bind()
        {
            dt = dll.GetDG(UNION_CODE).Tables[0];
            GridView1.DataSource = dt;
            GridView1.DataKeyNames = new string[] { "UNION_CODE" };//主键
            GridView1.PageSize = GridView1.PageSize;
            GridView1.DataBind();
            

        }
        /// <summary>
        /// 翻页操作
        /// 在GridView当前索引正在更改时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            bind();
        }
       

        protected void PageDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow pagerRow = GridView1.BottomPagerRow;
            DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
            GridView1.PageIndex = pageList.SelectedIndex;
            bind();   //数据绑定 
        }



        public string PageSize = "5";
        protected void PageSizeDropdownlist_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            GridViewRow pagerRow = GridView1.BottomPagerRow;
            DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageSizePageDropdownlist");
            GridView1.PageIndex = pageList.SelectedIndex;
            /*GridView1.PageSize= int.Parse(((System.Web.UI.WebControls.ListControl)sender).Text);*/
            DropDownList pagesizList = (DropDownList)pagerRow.Cells[0].FindControl("PageSizePageDropdownlist");
            PageSize = pagesizList.Text;
            GridView1.PageSize=int.Parse(pagesizList.Text);
            bind();   //数据绑定
        }
        protected void GridView1_DataBound(object sender, EventArgs e)
        {
            GridView1.BottomPagerRow.Visible = true;//只有一页数据的时候也再下面显示pagerrow,需要top的再加Top
            GridViewRow pagerRow = GridView1.BottomPagerRow;
            DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
            Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");

            DropDownList pagesizList = (DropDownList)pagerRow.Cells[0].FindControl("PageSizePageDropdownlist");

            pagesizList.Items.FindByText(PageSize).Selected = true;

            if (pageList != null)
            {
                for (int i = 0; i < GridView1.PageCount; i++)
                {
                    int pageNumber = i + 1;
                    ListItem item = new ListItem(pageNumber.ToString());
                    if (i == GridView1.PageIndex)
                    {
                        item.Selected = true;
                    }
                    pageList.Items.Add(item);
                }
            }

            if (pageLabel != null)
            {
                int currentPage = GridView1.PageIndex + 1;
                pageLabel.Text = "Page " + currentPage.ToString() +
                 " of " + GridView1.PageCount.ToString();

            }

           


        }

    }
}

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrganizationTable.aspx.cs" Inherits="LY.CCPCUEP.UI.Uep.html.OrganizationTable" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
     <link href="jquery.ztree/style.css" rel="stylesheet" />
    <link href="jquery.ztree/zTreeStyle.css" rel="stylesheet" />
    <script src="jquery.ztree/jquery-1.4.4.min.js"></script>
    <script src="jquery.ztree/jquery.ztree.core.js"></script>
    <script src="jOrgChart-master/jquery.min.js"></script>
      <style>
       
        .jOrgChart .node {
            padding: 6px 1px 2px 5px;
            border-radius: 3px;
            width: 200px;
            height: 20px;
            letter-spacing: 3px;
            border: 1px solid #726bf7;
          
        }

        
        
       
    </style>

</head>
<body>
    <form id="form1" runat="server">
          <div class="float_affter">
        <div style="width:20%;height:554px; float: left; border-right: 1px solid #cac5c3; box-sizing: border-box; overflow: auto; ">
            <ul id="treeDemo" class="ztree" style="margin-top:20px"></ul>
        </div>
              <div >
                   <iframe frameborder="no" style="width:80%; height:554px;" id="childframe" ></iframe>
          
              </div>
        </div>

    </form>
</body>
</html>

<script type="text/javascript">
    jQuery.noConflict();
    var zNodes;
    var zTree;
    //setting异步加载的设置
    var setting = {
        async: {
            enable: true, //表示异步加载生效
            url: "../Ajax/OrganizationalStructureAjax.ashx", // 异步加载时访问的页面
            autoParam: ["id"], // 异步加载时自动提交的父节点属性的参数
            otherParam: ["ajaxMethod", 'AnsyData'], //ajax请求时提交的参数
            type: 'post',
            dataType: 'json'
        },
        checkable: true,
        showIcon: true,
        showLine: true, // zTree显示连接线
        data: {  //用pId来标识父子节点的关系
            simpleData: {
                enable: true
            }
        },
        expandSpeed: "", // 设置 zTree 节点展开、折叠的动画速度,默认为"fast",""表示无动画
        callback: { // 回调函数
            onClick: zTreeOnClick, // 单击鼠标事件
            asyncSuccess: zTreeOnAsyncSuccess //异步加载成功事件
        }
    };
    
    $(document).ready(function () {
        //初始化
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);

         $('#childframe').attr('src','OgGridView.aspx')
      
    });
   
    function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
       // alert("异步加载");
    }


    

    //单击时获取zTree节点的Id,和value的值
    function zTreeOnClick(event, treeId, treeNode, msg) {
       
       $('#childframe').attr('src','OgGridView.aspx?UNION_CODE='+treeNode.id)
    };



    
</script>
using LY.CCPCUEP.BLL.UEP;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LY.CCPCUEP.UI.Uep.html
{
    public partial class OrganizationTable : System.Web.UI.Page
    {

        string treeNodeID = "234E45F0077881AAE0430AA3034681AA";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
      

        //绑定
        public void bind()
        {

            T_UEP_DB_ZTREEBLL dll = new T_UEP_DB_ZTREEBLL();

            DataTable dt = dll.GetDG(treeNodeID).Tables[0];
            //GridView1.DataSource = dt;
            //GridView1.DataKeyNames = new string[] { "UNION_CODE" };//主键
            //GridView1.DataBind();
           
        }

        //删除
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
         
            bind();
        }

        //更新
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            
            bind();
        }


        //取消
        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            //GridView1.EditIndex = -1;
            bind();
        }

    }
}

 

转载于:https://www.cnblogs.com/xiaz/p/10434585.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值