求助,导航栏排序问题?
本帖最后由 lincong19782 于 2013-03-30 10:27:53 编辑 各位大侠,请帮忙一下:
前台default.aspx
<%for (int i = 0; i <lists.Count; i++)
{ %> <%=classdic[lists[i]] %> <%} %>
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.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace Maticsoft.Web.Article
{
public partial class Detail : System.Web.UI.Page
{
protected Dictionary<string, string> classdic = new Dictionary<string, string>();//名称字典
protected List<string> lists = new List<string>();//编号泛型
protected Dictionary<string, int> orders = new Dictionary<string, int>();//排序号字典
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
{
GetClassList("135", 0);
}
else
{
Response.Write("<script>alert('已经是最后一篇了!');history.back(1);</script>");
}
}
}
protected void GetClassList(string ParentID, int Layer)
{
IDataReader dr = ClassListDAL(ParentID);
Dictionary<string, string> classdic1 = new Dictionary<string, string>();
List<string> lists1 = new List<string>();
while (dr.Read())
{
classdic1.Add(dr["ParentID"].ToString().Trim(), dr["Text"].ToString());
lists1.Add(dr["ParentID"].ToString().Trim());
orders.Add(dr["ParentID"].ToString().Trim(), int.Parse(dr["OrderID"].ToString()));
}
dr.Close();
for (int i = 0; i <classdic1.Count; i++)
{
string stxt = "";
if (Layer > 0)
stxt = " ";
for (int j = 1; j < Layer; j++)
{
stxt += " ";
}
classdic.Add(lists1[i], stxt + classdic1[lists1[i]]);
lists.Add(lists1[i]);
GetClassList(lists1[i], (Layer + 1));
}
}
protected IDataReader ClassListDAL(string ParentID)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);//数据库连接为我本地连接
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from [S_Tree] where NodeID=@parentID order by OrderID asc";
SqlParameter param = new SqlParameter("@parentID", ParentID);
cmd.Parameters.Add(param);
conn.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}