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# 簡單反射實現winform左側樹形導航,右側切換內容C#反射ORM
- Win10 隱藏左側邊側欄(導航視窗)中的資料夾Win10
- tpextbuilder- 左側樹形導航UI
- Win10資料夾右側資訊欄怎麼關閉?Win10資料夾右側資訊欄的關閉方法Win10
- uniapp實戰——實現右側資料的渲染APP
- 兩欄佈局,左側可伸縮,右側寬度自適應
- css左側欄固定右側欄寬度自適應程式碼例項CSS
- 左側分類導航選單
- 左側固定,右側自適應的佈局方式理解margin負值理論
- 七種實現左側固定,右側自適應兩欄佈局的方法
- weblogic 左側的樹無法顯示Web
- uniapp實戰——實現左側資料渲染和點選高亮APP
- jQuery實現左側分類選單jQuery
- 資料庫的集合,分頁及約束條件資料庫
- 實現左側固定寬度, 右側自適應的兩欄佈局常見方法
- 左側固定,右側自適應的佈局方式(新增評論區大佬教的方法)
- 靜默建立oracle資料庫及克隆資料庫Oracle資料庫
- 求問 mac 下 uiautomator 左側 view 樹空白MacUIView
- 【PG結構】Postgresql資料庫資料目錄說明SQL資料庫
- 電商左側商品分類選單實現
- OT部分頁面左側選單不顯示
- 【阿不】深入ASP.NET資料繫結(中)—資料雙向繫結機理ASP.NET
- 前端框架VUE——資料繫結及模板語法前端框架Vue
- CSS自適應佈局(左右固定 中間自適應或者右側固定 左側自適應)CSS
- 怎麼用Word做資料夾側面標籤?Word做資料夾側面標籤教程
- 恢復目錄資料庫(Recovery Catalog)作用及演示例項資料庫
- Data Guard備份資料庫位置及目錄的選擇方案資料庫
- Oracle資料庫索引使用及索引失效總結 轉Oracle資料庫索引
- Oracle資料庫管理——表資料庫高水位及shrink操作Oracle資料庫
- 摘:Oracle資料庫補丁分類、安裝及管理Oracle資料庫
- excel製作資料夾側標籤Excel
- 將ORACLE資料庫資料檔案遷移到其他目錄(ZT)Oracle資料庫
- [提問交流]切換頁面,左側選單消失
- JavaScript彈性固定於網頁右側詳解JavaScript網頁
- Python資料結構——解析樹及樹的遍歷Python資料結構
- Flask框架使用藍圖劃分目錄、g物件、使用資料庫連線池連結資料庫Flask框架物件資料庫
- 【MySQL 資料庫】MySQL目錄MySql資料庫
- 樹型結構資料在資料庫基本表中的儲存及維護 (轉)資料庫