?? createtreeajax.aspx.cs
字號:
?// (c) Copyright XXXXXXX Corporation.
// 無級別限制Aajx樹型菜單
// See http://www.ddyuanlin.com/test/tree.aspx
// Email:alphacn@126.com
// 2007.9.19 Alpha
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
/// <summary>
/// 生成當前結點子樹
/// </summary>
public partial class Manage_BaseData_CreateTreeAjax : System.Web.UI.Page
{
//數據庫連接字符串
private const string CONNSTRING = "server=.;database=PubData;uid=sa;pwd=123456";
//當前結點代碼
private string BaseDataCode = "";
//Sql代碼
private string Sqlstr = "";
//樣式名稱
private string ClassName="";
//孫子結點數目
private int SubCount;
//子結點數目
private int PrantCount;
//DataSet對象
private DataSet Ds;
//子結點代碼
private string BaseCode = "";
//子結點名稱
private string BaseName = "";
//Javascript事件名
private string JsAction="";
//樣式表名稱
private string IfShowClass = "";
//子符串變量
StringBuilder Sb;
/// <summary>
/// 頁面初始化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
//獲得當前結點代碼
BaseDataCode = Request.QueryString["ID"];
if (BaseDataCode != "" || BaseDataCode != "")
{
Sqlstr = "SELECT BaseDataCode, BaseDataName, LevelType,ParentCode FROM SysBaseData WHERE (ParentCode = '" + BaseDataCode + "') AND (VaildType = '0') ORDER BY SerialNumberID";
using (SqlConnection Conn = new SqlConnection(CONNSTRING))
{
SqlDataAdapter Da = new SqlDataAdapter(Sqlstr, Conn);
Conn.Open();
Ds = new DataSet();
Da.Fill(Ds,"Dt");
Sb = new StringBuilder();
//當前結點的子結點數量
PrantCount = Ds.Tables["Dt"].Rows.Count;
//循環讀出子點結點
for (int i = 0; i < PrantCount;i++ )
{
//子結點代碼
BaseCode = Ds.Tables["Dt"].Rows[i][0].ToString().Trim();
//子結點名稱
BaseName = Ds.Tables["Dt"].Rows[i][1].ToString().Trim();
//判斷該結點下,是否還有子結點
Sqlstr = "SELECT count(BaseDataCode) from SysBaseData where ParentCode='" + BaseCode + "'";
SqlCommand cmd2 = new SqlCommand(Sqlstr, Conn);
//當前結點子結點的子結點數量
SubCount = int.Parse(cmd2.ExecuteScalar().ToString());
//是否有孫子結點
if (SubCount > 0)
{
//最后一個結點
if (i == PrantCount - 1)
{
ClassName = "folder_close_end";
IfShowClass = "";
}
else
{
ClassName = "folder_close";
IfShowClass = "class='list0'";
}
JsAction ="onclick=\"GetData('" + BaseCode + "')\"";
}
else
{
//最后一個結點
if (i == PrantCount - 1)
{
ClassName = "file_end";
IfShowClass = "";
}
else
{
ClassName = "file";
IfShowClass = "class='list0'";
}
JsAction = "";
}
//生成子樹代碼
Sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
Sb.Append("<tr><td><div id='M1_" + BaseCode + "' class='" + ClassName + "'" + JsAction + " alt='" + BaseName + "'><a href='#" + BaseCode + "'' >" + BaseName + "</a></div>");
Sb.Append("<div id='M2_" + BaseCode + "' style='display:none' " + IfShowClass + "></div></td></tr>");
Sb.Append("</table>");
}
//輸出
Response.Write(Sb.ToString());
}
}
else
{
Response.Write("沒有數據");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -