文章发布的问题 我做的是杂志网站,我想实现杂志的发布,一级目录:期刊号,二级目录:栏目,三级目录:文章。首先栏目是动态的,我希望栏目有一部分“人生”、“情感”等是本来就有,但是有时候也可以添加栏目,但是我不知道怎么保存期刊号和栏目号之间的关系,还有在后台显示文章列表这一块,怎么显示?因为涉及到三个表,最重要的是如果修改栏目的信息,对文章的影响该如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ws_hgo/archive/2009/11/20/4842026.aspxnamespace XR.Web { using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.Sql; using System.Data.SqlClient; public partial class Default2 : System.Web.UI.Page { DataTable Tables = new DataTable(); DataColumn DC = new DataColumn(); DataRow DR; ProductCategoryBLL Category = new ProductCategoryBLL(); protected void Page_Load(object sender, EventArgs e) { DataTable DT = Category.GetDataTable("YLProductCategory", 0); CreateDataTable(); GetTree(DT, 0, 0); DropDownList1.DataSource = Tables; DropDownList1.DataTextField = "Title"; DropDownList1.DataValueField = "ID"; DropDownList1.DataBind(); } public void GetTree(DataTable DT,int PID,int Depth) { DataView DV = DT.DefaultView; DV.RowFilter = "ParentID=" + PID; string str = string.Empty; if (Depth == 0) { str = ""; } else if (Depth == 1) { str = "├"; } else { for (int i = 0; i < Depth; i++) { str =str+"├" + "" + "-"; } } foreach (DataRowView Drv in DV) { int ID = int.Parse(Drv["ID"].ToString()); string Title = Drv["Title"].ToString(); int ParentID = int.Parse(Drv["ParentID"].ToString()); int Dep = int.Parse(Drv["Depth"].ToString()); DR = Tables.NewRow(); DR["ID"] = ID; DR["Title"] = str + Title; DR["ParentID"] = ParentID; DR["Depth"] = Dep; Tables.Rows.Add(DR); int n = Dep; n++; GetTree(DT,ID, n); } } public void CreateDataTable() { DC = new DataColumn(); DC.ColumnName = "ID"; DC.DataType = System.Type.GetType("System.Int32"); Tables.Columns.Add(DC); DC = new DataColumn(); DC.ColumnName = "Title"; DC.DataType = System.Type.GetType("System.String"); Tables.Columns.Add(DC); DC = new DataColumn(); DC.ColumnName = "ParentID"; DC.DataType = System.Type.GetType("System.Int32"); Tables.Columns.Add(DC); DC = new DataColumn(); DC.ColumnName = "Depth"; DC.DataType = System.Type.GetType("System.Int32"); Tables.Columns.Add(DC); } } } 不需要三个表吧?一个就够了。菜单树即可解决。犹如CSND的目录树 Create table Journals (JID int IDENTITY (1, 1) primary key, Jname varchar(20) unique, Jimage varchar(100), state varchar(20) default '建设中', Jtime datetime null,) Create table Lanmu (LID int IDENTITY (1, 1) primary key, CNAME varchar(20) not null, ) Create table Articles (ARID varchar(9) primary key, ATitle varchar(20) not null, Acontent text not null, Adate Datetime not null, LID int not null, AID varchar(20) not null, JID int not null, EID int not null, Foreign key(AID) references Authors(AID), Foreign key(CID) references Lanmu(CID), Foreign key(JID) references Journals(JID), Foreign key(EID) references Editors(EID) ) 应该是树状结构,使用treeview递归绑定数据 asp.net如何使用后台数据绑定Treeview呢? 救命~~~:调试时,无法定位到dll中的类。搞了一天啦~~~~~~ 关于javascript在.Net中应用的问题 关于异常的使用. (求9)ASP.NET中提交IFRAM到父页面问题 用datagird来显示下面的数据 如何用得到的MAC 生成注册码? asp.net2.0 access连接问题 在asp.net中怎样用js传参,执行后台方法,最好ajax方式,但是我对这种不熟悉,希望有个简单的案例 翻页就读不数据!原因在IsPostBack. ●●●●●●●关于FreeTextBox设置的问题?●●●●●● 求助!
{
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
DataTable Tables = new DataTable();
DataColumn DC = new DataColumn();
DataRow DR;
ProductCategoryBLL Category = new ProductCategoryBLL();
protected void Page_Load(object sender, EventArgs e)
{
DataTable DT = Category.GetDataTable("YLProductCategory", 0);
CreateDataTable();
GetTree(DT, 0, 0);
DropDownList1.DataSource = Tables;
DropDownList1.DataTextField = "Title";
DropDownList1.DataValueField = "ID";
DropDownList1.DataBind();
}
public void GetTree(DataTable DT,int PID,int Depth)
{
DataView DV = DT.DefaultView;
DV.RowFilter = "ParentID=" + PID;
string str = string.Empty;
if (Depth == 0)
{
str = "";
}
else if (Depth == 1)
{
str = "├";
}
else
{
for (int i = 0; i < Depth; i++)
{
str =str+"├" + "" + "-";
}
}
foreach (DataRowView Drv in DV)
{
int ID = int.Parse(Drv["ID"].ToString());
string Title = Drv["Title"].ToString();
int ParentID = int.Parse(Drv["ParentID"].ToString());
int Dep = int.Parse(Drv["Depth"].ToString());
DR = Tables.NewRow();
DR["ID"] = ID;
DR["Title"] = str + Title;
DR["ParentID"] = ParentID;
DR["Depth"] = Dep;
Tables.Rows.Add(DR);
int n = Dep;
n++;
GetTree(DT,ID, n);
}
}
public void CreateDataTable()
{
DC = new DataColumn();
DC.ColumnName = "ID";
DC.DataType = System.Type.GetType("System.Int32");
Tables.Columns.Add(DC);
DC = new DataColumn();
DC.ColumnName = "Title";
DC.DataType = System.Type.GetType("System.String");
Tables.Columns.Add(DC);
DC = new DataColumn();
DC.ColumnName = "ParentID";
DC.DataType = System.Type.GetType("System.Int32");
Tables.Columns.Add(DC);
DC = new DataColumn();
DC.ColumnName = "Depth";
DC.DataType = System.Type.GetType("System.Int32");
Tables.Columns.Add(DC);
}
}
}
(JID int IDENTITY (1, 1) primary key,
Jname varchar(20) unique,
Jimage varchar(100),
state varchar(20) default '建设中',
Jtime datetime null,)
Create table Lanmu
(LID int IDENTITY (1, 1) primary key,
CNAME varchar(20) not null,
) Create table Articles
(ARID varchar(9) primary key,
ATitle varchar(20) not null,
Acontent text not null,
Adate Datetime not null,
LID int not null,
AID varchar(20) not null,
JID int not null,
EID int not null,
Foreign key(AID) references Authors(AID),
Foreign key(CID) references Lanmu(CID),
Foreign key(JID) references Journals(JID),
Foreign key(EID) references Editors(EID)
)