显示页面:<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlTarget" runat="server">
</asp:DropDownList>
</div>
</form>
</body>
</html>
程序层面:
public partial class sys_admin_system_test : System.Web.UI.Page
{
private string toadd = "├";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetArticleCategory("0");
this.ddlTarget.Items.Insert(0, new ListItem("Search All", "all"));
}
}
private void GetArticleCategory(string pid)
{
SqlConnection conn = new SqlConnection(SQLHelper.SQLServerConnStr);
string sql = "select id,classname,fatherid from sys_class where typeid=2 and fatherid=@pid order by orderlist";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter Pid = new SqlParameter("@pid", SqlDbType.Int);
Pid.Value = pid;
cmd.Parameters.Add(Pid);
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
this.ddlTarget.Items.Add(new ListItem(toadd + " " + sdr[1].ToString(), sdr[0].ToString()));
toadd += "─┴";
this.GetArticleCategory(sdr[0].ToString());
toadd = toadd.Substring(0, toadd.Length - 2);
}
sdr.Close();
conn.Close();
}