📄 tree_travelsal.aspx.cs
字号:
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;
public partial class Tree_travelsal : System.Web.UI.Page
{
private string tablename="tree";
int current=0;
int len = 0;
string[] arrPowerName;
string ConnectionString;
public Tree_travelsal()
{
this.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
len = this.GetRecordCount();
arrPowerName = new string[len];
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetPowerName(0);
//ResponseArray();
}
}
private void GetPowerName(int _ParentId)
{
int id;
string PowerName;
string sql = "select Id,PowerName,Layer from " + tablename + " where ParentId=" + _ParentId;
try
{
SqlConnection conn=new SqlConnection(ConnectionString);
conn.Open();
SqlCommand cmd=new SqlCommand(sql,conn);
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
for(int j=0;j<int.Parse(dr["Layer"].ToString());j++)
{
Response.Write("  ");
}
PowerName=dr["PowerName"].ToString();
Response.Write("<a href='#'>"+PowerName + "</a><br>");
arrPowerName[current++] = PowerName;
id=int.Parse(dr["id"].ToString());
GetPowerName(id);
}
dr.Close();
conn.Close();
}
catch(Exception e)
{}
}
private int GetRecordCount()
{
SqlConnection conn = new SqlConnection(ConnectionString);
string sql = "select count(*) id from " + tablename;
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
int count = int.Parse(cmd.ExecuteScalar().ToString());
conn.Close();
return count;
}
private void ResponseArray()
{
int i;
for (i = 0; i < len; i++)
{
Response.Write(arrPowerName[i] + "<br>");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -