Database design:
--Unlimited Classification----Database: Db_infinitecategory--Data sheet: Tb_infinite-----------------------------------------------------------------Create a databaseCREATE DATABASEdb_infinitecategory--Create a data table Usedb_infinitecategoryCREATE TABLETb_infinite (IDint not NULL,--sub-levelPidint not NULL,--Parent LevelCategoryNamevarchar(Ten) not NULL --Category name)--using StatementsSelectID, PID, CategoryName fromTb_infinitewherePid= 0
Code:
1 usingSystem;2 usingSystem.Web.UI;3 usingSystem.Data;4 usingSystem.Data.SqlClient;5 6 usingDAL;7 usingSystem.Web.UI.WebControls;8 9 namespaceinfinitecategoryTen { One Public Partial classDefault:System.Web.UI.Page A { - stringToadd ="├"; - the protected voidPage_Load (Objectsender, EventArgs e) - { - if(!Page.IsPostBack) - { +Getarticlecategory ("0"); - } + } A at Public voidGetarticlecategory (stringpid) - { -SqlConnection conn =NewSqlConnection ("server = huangfu-pc; database = db_infinitecategory; Integrated Security = True"); - stringsql ="Select Id,categoryname from tb_infinite where [email protected]"; -SqlCommand cmd =NewSqlCommand (SQL, conn); -SqlParameter Pid =NewSqlParameter ("@pid", SqlDbType.Int); inPid.value =pid; - cmd. Parameters.Add (Pid); to Conn. Open (); +SqlDataReader SDR =cmd. ExecuteReader (); - while(SDR). Read ()) the { * This. DROPDOWNLIST1.ITEMS.ADD (NewListItem (Toadd +" "+ sdr[1]. ToString (), sdr[0]. ToString ())); $Toadd + ="─┴";Panax Notoginseng This. Getarticlecategory (sdr[0]. ToString ()); -Toadd = Toadd. Substring (0, Toadd. Length-2); the } + SDR. Close (); A Conn. Close (); the } + } -}
Final effect:
ASP-Infinite Pole classification