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()));
    }
}

 

 

 

 

相关文章
|
2月前
|
SQL 开发框架 .NET
ASP.NET连接SQL数据库:详细步骤与最佳实践指南ali01n.xinmi1009fan.com
随着Web开发技术的不断进步,ASP.NET已成为一种非常流行的Web应用程序开发框架。在ASP.NET项目中,我们经常需要与数据库进行交互,特别是SQL数据库。本文将详细介绍如何在ASP.NET项目中连接SQL数据库,并提供最佳实践指南以确保开发过程的稳定性和效率。一、准备工作在开始之前,请确保您
221 3
|
4月前
|
SQL 开发框架 数据库
".NET开发者的超能力:AgileEAS.NET ORM带你穿越数据库的迷宫,让数据操作变得轻松又神奇!"
【8月更文挑战第16天】AgileEAS.NET是面向.NET平台的企业应用开发框架,核心功能包括数据关系映射(ORM),允许以面向对象方式操作数据库,无需编写复杂SQL。通过继承`AgileEAS.Data.Entity`创建实体类对应数据库表,利用ORM简化数据访问层编码。支持基本的CRUD操作及复杂查询如条件筛选、排序和分页,并可通过导航属性实现多表关联。此外,提供了事务管理功能确保数据一致性。AgileEAS.NET的ORM简化了数据库操作,提升了开发效率和代码可维护性。
54 5
|
15天前
|
数据库 C# 开发者
ADO.NET连接到南大通用GBase 8s数据库
ADO.NET连接到南大通用GBase 8s数据库
|
25天前
|
存储 缓存 NoSQL
2款使用.NET开发的数据库系统
2款使用.NET开发的数据库系统
|
14天前
|
数据库连接 数据库 C#
Windows下C# 通过ADO.NET方式连接南大通用GBase 8s数据库(上)
Windows下C# 通过ADO.NET方式连接南大通用GBase 8s数据库(上)
|
14天前
|
数据库连接 数据库 C#
Windows下C# 通过ADO.NET方式连接南大通用GBase 8s数据库(下)
本文接续前文,深入讲解了在Windows环境下使用C#和ADO.NET操作南大通用GBase 8s数据库的方法。通过Visual Studio 2022创建项目,添加GBase 8s的DLL引用,并提供了详细的C#代码示例,涵盖数据库连接、表的创建与修改、数据的增删查改等操作,旨在帮助开发者提高数据库管理效率。
|
2月前
|
存储 NoSQL API
.NET NoSQL 嵌入式数据库 LiteDB 使用教程
.NET NoSQL 嵌入式数据库 LiteDB 使用教程~
|
2月前
|
SQL 开发框架 .NET
ASP.NET连接SQL数据库:实现过程与关键细节解析an3.021-6232.com
随着互联网技术的快速发展,ASP.NET作为一种广泛使用的服务器端开发技术,其与数据库的交互操作成为了应用开发中的重要环节。本文将详细介绍在ASP.NET中如何连接SQL数据库,包括连接的基本概念、实现步骤、关键代码示例以及常见问题的解决方案。由于篇幅限制,本文不能保证达到完整的2000字,但会确保
|
2月前
|
数据库
Admin.Net根据域名自动选择数据库
Admin.Net根据域名自动选择数据库
18 0
|
3月前
|
SQL 存储 关系型数据库
C#一分钟浅谈:使用 ADO.NET 进行数据库访问
【9月更文挑战第3天】在.NET开发中,与数据库交互至关重要。ADO.NET是Microsoft提供的用于访问关系型数据库的类库,包含连接数据库、执行SQL命令等功能。本文从基础入手,介绍如何使用ADO.NET进行数据库访问,并提供示例代码,同时讨论常见问题及其解决方案,如连接字符串错误、SQL注入风险和资源泄露等,帮助开发者更好地利用ADO.NET提升应用的安全性和稳定性。
321 6

推荐镜像

更多