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

效果图如下:

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

 

 

 

 

上一篇:【目录】C#搭建足球赛事资料库与预测平台与彩票数据分析目录


下一篇:linux 更改mysql的数据库目录