asp.net Oracle数据库左侧目录树及右侧数据绑定及分页

简介: 效果图如下:  当前位置:水利管理 >> ...

效果图如下:

 
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="SLGL_List.aspx.cs" Inherits="SLGL_List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
   <div id="warp">
         <div class="nyl">
    <div class="position"><img src="images/home2.png" />当前位置:水利管理 >> 
                        <span style="color: #0376B9;">
                            <asp:Label Text="" ID="lblPos" runat="server" /></span></div>
    <div class="sideBar">
     <div class="sideBar_title">
      <span><img src="images/noticico.jpg" /></span>
      <h1>水利管理</h1>             </div>
     <div class="sideBar_menu">
    <ul id="leftlist" runat="server">
             </ul>
    </div>
  </div>
    <div class="sidebar_r">
      <div class="ctllf_title"><asp:Label ID="lblMsg" runat="server" class="tab1_bg"></asp:Label></div>
   <div class="ctllf_txt2">
    <ul class="right_mid" id="detailslist" runat="server">
    </ul>
    <div class="pagination">
     共<asp:Label ID="lblTotal" runat="server"></asp:Label>条记录 <asp:Label ID="lblCurrentPage" runat="server"></asp:Label>/<asp:Label ID="lblPageNumber" runat="server"></asp:Label> 页  
     <asp:LinkButton id="aFirst" runat="server" CausesValidation="false" OnCommand="aFirst_OnCommand">首页</asp:LinkButton> 
     <asp:LinkButton id="aPre" runat="server" CausesValidation="false" OnCommand="aPre_OnCommand">上一页</asp:LinkButton> 
     <asp:LinkButton id="aNext" runat="server" CausesValidation="false" OnCommand="aNext_OnCommand">下一页</asp:LinkButton> 
     <asp:LinkButton id="aLast" runat="server"  CausesValidation="false" OnCommand="aLast_OnCommand">尾页</asp:LinkButton> 
      第
     <asp:DropDownList ID="ddlPageNumber" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPageNumber_OnSelectedIndexChaged"></asp:DropDownList>
     页
    </div>     
   </div>
    </div>
  </div>
  <div class="clear"></div>
</div>
<div class="conbotbg"></div>
<asp:HiddenField ID="hf" runat="server" Value="T1" />
<script type="text/javascript">
    $(function () {
        $("#ContentPlaceHolder1_leftlist >li").each(function (i) {
            if ($(this).attr("id") == $("#<%=hf.ClientID%>").val()) {
                $(this).find("a").css("color", "red");
            }
            else {
                $(this).find("a").css("color", "black");
            }
        });
    });
</script>
</asp:Content>




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using USTC;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;

public partial class SLGL_List : System.Web.UI.Page
{
    OracleDM dm = new OracleDM();

    public string TYPE = ""; //类型
    public int CURRENT_PAGE_INDEX = 1; //当前页数
    public int PAGE_SIZE = 11; //每页显示记录条数
    public int TOTAL_DATA = 0; //总记录条数
    public int PAGE_NUMBER = 1; //页数(计算值)

    /// <summary>
    /// 内容页中找母版页中的控件,并设置颜色
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void Page_LoadComplete(Object sender, EventArgs e)
    {
        (Master.FindControl("mT1") as HtmlAnchor).Attributes.Remove("class");
    }

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

            BindKSXX();//先动态绑定科室信息
            string type = "";
            if (Request.QueryString["ID"] != null)
            {
                string Id = Request.QueryString["ID"].ToString();
                type = getType(Id);
            }
            if (Request.QueryString["type"] != null)
            {
                type = Server.UrlDecode(Request.QueryString["type"].ToString());
            }
            else
            {
                type = "水利管理";
            }
            if (Request.QueryString["pid"] != null)
            {
                hf.Value = Request.QueryString["pid"].ToString();
            }

            ViewState["TYPE"] = type;
            this.lblPos.Text = type;
            this.lblMsg.Text = type;
            ViewState["CURRENT_PAGE_INDEX"] = CURRENT_PAGE_INDEX;
            getTotalRecordNumbers(type);
            BindContentByMenuAndPageSize(type, PAGE_SIZE, 1); //默认显示当前类别的第一页数据
            this.lblTotal.Text = TOTAL_DATA.ToString(); //总记录条数
            PAGE_NUMBER = (int)Math.Ceiling(((decimal)TOTAL_DATA) / ((decimal)PAGE_SIZE));
            ViewState["PAGE_NUMBER"] = PAGE_NUMBER;
            this.lblPageNumber.Text = PAGE_NUMBER.ToString(); //总记录页数
            this.lblCurrentPage.Text = "1";
            if (TOTAL_DATA == 0)
            {
                this.lblPageNumber.Text = "1";
            }
            if (this.lblCurrentPage.Text == this.lblPageNumber.Text)
            {
                //就一页的话,四个按钮均不可用
                this.aFirst.Enabled = false;
                this.aPre.Enabled = false;
                this.aNext.Enabled = false;
                this.aLast.Enabled = false;
            }
            BindDropDownList();
        }
    }


    public string getType(string Id)
    {
        string type = "";
        string sql = "select * from T_SMALLCLASS where BIGID=(select ID from T_BIGCLASS where  TITLE='水利管理') and ID='" + Id + "'";
        DataSet ds = dm.getsql(sql);
        if (ds.Tables[0].Rows.Count > 0 && ds != null)
        {
            type = ds.Tables[0].Rows[0]["TITLE"].ToString().Trim();
        }
        else
        {
            type = "水利管理";
        }
        return type;
    }

    /// <summary>
    /// 防汛抗旱子目录菜单动态绑定
    /// </summary>
    public void BindKSXX()
    {
        StringBuilder sb = new StringBuilder();
        string sql = "select * from T_SMALLCLASS where BIGID=(select ID from T_BIGCLASS where  TITLE='水利管理')";
        DataSet ds = dm.getsql(sql);
        int index = 1;
        if (ds != null && ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRowView drv in ds.Tables[0].DefaultView)
            {
                sb.Append("<li id=\"T" + index + "\" runat=\"server\"><a title=\"" + drv["TITLE"].ToString().Trim() + "\" href=\"SLGL_List.aspx?type=" + Server.UrlEncode(drv["TITLE"].ToString().Trim()) + "&mId=mT7&pid=T" + index + "\">" + drv["TITLE"].ToString().Trim() + "</a></li>");
                index++;
            }
        }
        else
        {

        }
        this.leftlist.InnerHtml = sb.ToString();
    }

    /// <summary>
    /// 获取总的记录条数
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public int getTotalRecordNumbers(string type)
    {
        string sql = @"select ID, TITLE,S_Content,ReleaseTime from (select  a.ID, a.SMALLID,a.Title,a.RELEASETIME RELEASETIME , b.Title bTitle,b.s_Content  from  t_leastclass  a left join t_smallclass   b on a.SMALLID=b.ID and b.Title='" + type + @"' where b.ID in(select a.id from  t_smallclass a left join t_bigclass b on a.BigID=b.id where b.Title='水利管理') order by a.RELEASETIME desc)";
        DataSet ds = dm.getsql(sql);
        TOTAL_DATA = ds.Tables[0].Rows.Count;
        return TOTAL_DATA;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="type"></param>
    /// <param name="pageSize"></param>
    /// <param name="pageIndex"></param>
    public void BindContentByMenuAndPageSize(string type, int pageSize, int pageIndex)
    {
        StringBuilder sb = new StringBuilder();
        string sql = @"select ID, TITLE,S_Content,ReleaseTime,orderNumber  from (select  a.ID, a.SMALLID,a.Title,a.RELEASETIME RELEASETIME , b.Title bTitle,b.s_Content,row_number() over(order by a.RELEASETIME desc) orderNumber  from         
   t_leastclass  a left join t_smallclass   b on a.SMALLID=b.ID and b.Title='" + type + @"' where b.ID in(select a.id from  t_smallclass a left    
             join t_bigclass b on a.BigID=b.id where b.Title='水利管理') order by a.RELEASETIME desc)where orderNumber between " + ((pageIndex - 1) * pageSize + 1) + " and  " + pageIndex * pageSize + "";
        DataSet ds = dm.getsql(sql);
        foreach (DataRowView drv in ds.Tables[0].DefaultView)
        {
            sb.Append("<li><a title=\"" + drv["TITLE"].ToString().Trim() + "\" href=\"lashgc.aspx?ID=" + drv["ID"] + "&mId=mT7\" target=\"_blank\"><div class=\"f_time\">" + DateTime.Parse(drv["ReleaseTime"].ToString()).ToString("yyyy-MM-dd") + "</div>" + drv["TITLE"].ToString() + "</a></li>");
        }
        this.detailslist.InnerHtml = sb.ToString();
    }


    /// <summary>
    /// 首页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void aFirst_OnCommand(object sender, CommandEventArgs e)
    {
        this.aFirst.Enabled = false;
        this.aPre.Enabled = false;
        this.aLast.Enabled = true;
        this.aNext.Enabled = true;

        BindContentByMenuAndPageSize(ViewState["TYPE"].ToString(), PAGE_SIZE, int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()));
        this.lblCurrentPage.Text = "1";
        ViewState["CURRENT_PAGE_INDEX"] = "1";
    }

    /// <summary>
    /// 上一页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void aPre_OnCommand(object sender, CommandEventArgs e)
    {

        ViewState["CURRENT_PAGE_INDEX"] = int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()) - 1;
        this.lblCurrentPage.Text = int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()).ToString();
        BindContentByMenuAndPageSize(ViewState["TYPE"].ToString(), PAGE_SIZE, int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()));
        if (int.Parse(this.lblCurrentPage.Text) == int.Parse(this.lblPageNumber.Text))
        {
            this.aLast.Enabled = false;
            this.aNext.Enabled = false;
        }
        else
        {
            this.aLast.Enabled = true;
            this.aNext.Enabled = true;
        }
        if (Convert.ToInt32(lblCurrentPage.Text) == 1)
        {
            this.aPre.Enabled = false;
            this.aFirst.Enabled = false;
        }
        else
        {
            this.aPre.Enabled = true;
            this.aFirst.Enabled = true;
        }
        this.ddlPageNumber.ClearSelection();
        this.ddlPageNumber.Items.FindByText(this.lblCurrentPage.Text.Trim()).Selected = true;
    }

    /// <summary>
    /// 下一页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void aNext_OnCommand(object sender, CommandEventArgs e)
    {

        ViewState["CURRENT_PAGE_INDEX"] = int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()) + 1;
        this.lblCurrentPage.Text = int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()).ToString();
        BindContentByMenuAndPageSize(ViewState["TYPE"].ToString(), PAGE_SIZE, int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()));
        if (int.Parse(this.lblCurrentPage.Text) == int.Parse(this.lblPageNumber.Text))
        {
            this.aLast.Enabled = false;
            this.aNext.Enabled = false;
        }
        else
        {
            this.aLast.Enabled = true;
            this.aNext.Enabled = true;
        }
        if (Convert.ToInt32(lblCurrentPage.Text) + 1 > 1)
        {
            this.aPre.Enabled = true;
            this.aFirst.Enabled = true;
        }
        else
        {
            this.aPre.Enabled = false;
            this.aFirst.Enabled = false;
        }
        this.ddlPageNumber.ClearSelection();
        this.ddlPageNumber.Items.FindByText(this.lblCurrentPage.Text.Trim()).Selected = true;
    }

    /// <summary>
    /// 尾页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void aLast_OnCommand(object sender, CommandEventArgs e)
    {
        ViewState["CURRENT_PAGE_INDEX"] = ViewState["PAGE_NUMBER"];
        this.aLast.Enabled = false;
        this.aNext.Enabled = false;
        this.aFirst.Enabled = true;
        this.aPre.Enabled = true;
        BindContentByMenuAndPageSize(ViewState["TYPE"].ToString(), PAGE_SIZE, int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()));
        this.lblCurrentPage.Text = int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()).ToString();
    }

    public string MyContent3(string input)
    {
        string ret = "";

        if (string.IsNullOrEmpty(input))
        {
            ret = "";
        }
        else
        {
            if (input.Length > 8)
            {
                ret = input.Substring(0, 10);
            }
            else
            {
                ret = input;
            }
        }
        return ret;
    }

    public void BindDropDownList()
    {
        int page = int.Parse(ViewState["PAGE_NUMBER"].ToString());
        if (page == 0)
        {
            //没有记录
            ddlPageNumber.Items.Add(new ListItem("1"));
        }
        else
        {
            //有记录
            for (int i = 1; i <= page; i++)
            {
                ddlPageNumber.Items.Add(new ListItem(i.ToString()));
            }
        }

    }

    public void ddlPageNumber_OnSelectedIndexChaged(object sender, EventArgs e)
    {
        ViewState["CURRENT_PAGE_INDEX"] = (sender as DropDownList).SelectedItem.Text;
        this.lblCurrentPage.Text = int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()).ToString();
        if (int.Parse(this.lblCurrentPage.Text) == int.Parse(this.lblPageNumber.Text))
        {
            this.aLast.Enabled = false;
            this.aNext.Enabled = false;
        }
        else
        {
            this.aLast.Enabled = true;
            this.aNext.Enabled = true;
        }
        if (Convert.ToInt32(lblCurrentPage.Text) + 1 > 1)
        {
            this.aPre.Enabled = true;
            this.aFirst.Enabled = true;
        }
        else
        {
            this.aPre.Enabled = false;
            this.aFirst.Enabled = false;
        }
        BindContentByMenuAndPageSize(ViewState["TYPE"].ToString(), PAGE_SIZE, int.Parse(ViewState["CURRENT_PAGE_INDEX"].ToString()));
    }
}

 

 

 

 

相关文章
|
20天前
|
SQL Oracle 关系型数据库
Oracle数据库优化方法
【10月更文挑战第25天】Oracle数据库优化方法
26 7
|
20天前
|
Oracle 关系型数据库 数据库
oracle数据库技巧
【10月更文挑战第25天】oracle数据库技巧
22 6
|
20天前
|
存储 Oracle 关系型数据库
Oracle数据库优化策略
【10月更文挑战第25天】Oracle数据库优化策略
18 5
|
27天前
|
存储 Oracle 关系型数据库
数据库数据恢复—Oracle ASM磁盘组故障数据恢复案例
Oracle数据库数据恢复环境&故障: Oracle ASM磁盘组由4块磁盘组成。Oracle ASM磁盘组掉线 ,ASM实例不能mount。 Oracle数据库故障分析&恢复方案: 数据库数据恢复工程师对组成ASM磁盘组的磁盘进行分析。对ASM元数据进行分析发现ASM存储元数据损坏,导致磁盘组无法挂载。
|
9天前
|
SQL 关系型数据库 MySQL
12 PHP配置数据库MySQL
路老师分享了PHP操作MySQL数据库的方法,包括安装并连接MySQL服务器、选择数据库、执行SQL语句(如插入、更新、删除和查询),以及将结果集返回到数组。通过具体示例代码,详细介绍了每一步的操作流程,帮助读者快速入门PHP与MySQL的交互。
24 1
|
11天前
|
SQL 关系型数据库 MySQL
go语言数据库中mysql驱动安装
【11月更文挑战第2天】
26 4
|
1月前
|
存储 关系型数据库 MySQL
Mysql(4)—数据库索引
数据库索引是用于提高数据检索效率的数据结构,类似于书籍中的索引。它允许用户快速找到数据,而无需扫描整个表。MySQL中的索引可以显著提升查询速度,使数据库操作更加高效。索引的发展经历了从无索引、简单索引到B-树、哈希索引、位图索引、全文索引等多个阶段。
61 3
Mysql(4)—数据库索引
|
18天前
|
监控 关系型数据库 MySQL
数据库优化:MySQL索引策略与查询性能调优实战
【10月更文挑战第27天】本文深入探讨了MySQL的索引策略和查询性能调优技巧。通过介绍B-Tree索引、哈希索引和全文索引等不同类型,以及如何创建和维护索引,结合实战案例分析查询执行计划,帮助读者掌握提升查询性能的方法。定期优化索引和调整查询语句是提高数据库性能的关键。
85 1
|
20天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。同时,文章还对比了编译源码安装与使用 RPM 包安装的优缺点,帮助读者根据需求选择最合适的方法。通过具体案例,展示了编译源码安装的灵活性和定制性。
61 2
|
23天前
|
存储 关系型数据库 MySQL
MySQL vs. PostgreSQL:选择适合你的开源数据库
在众多开源数据库中,MySQL和PostgreSQL无疑是最受欢迎的两个。它们都有着强大的功能、广泛的社区支持和丰富的生态系统。然而,它们在设计理念、性能特点、功能特性等方面存在着显著的差异。本文将从这三个方面对MySQL和PostgreSQL进行比较,以帮助您选择更适合您需求的开源数据库。
89 4

推荐镜像

更多