读书人

导航栏排序有关问题

发布时间: 2013-04-02 12:35:26 作者: rapoo

求助,导航栏排序问题?
本帖最后由 lincong19782 于 2013-03-30 10:27:53 编辑 各位大侠,请帮忙一下:
前台default.aspx

<%for (int i = 0; i <lists.Count; i++)

{ %> <%=classdic[lists[i]] %> <%} %>


后台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.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);



}




现在前台显示的是:a >b > c
我想让它显示:c >b >a

请教要如何改动,谢谢! 导航?排序
[解决办法]

改成
<%for (int i = lists.Count-1; i>=0; i--)

{ %> <%=classdic[lists[i]] %> <%} %>

读书人网 >C#

热点推荐