//绑定所有目录
public static void Bind_list(DropDownList DropDownList1)
{
DropDownList1.Items.Clear();
string sql = "SELECT list_id,list_name,list_parent FROM list";
DataTable dt = DataBase.getDataTable(sql); //根据SQL语句获取DataTable值
Bind_list(DropDownList1,dt, "0", 0);
}
private static void Bind_list(DropDownList DropDownList1, DataTable dt, string parent, int grade)
{
DataRow[] dr = dt.Select("list_parent=" + parent, "list_id asc");
if (dr.Length > 0)
{
int grade1 = grade + 1;
foreach (DataRow row in dr)
{
ListItem li = new ListItem();
li.Text = "";
for (int i = 0; i < grade; i++)
{
li.Text += " ";
}
li.Text += "├" + row[1].ToString();
li.Value = row[0].ToString();
DropDownList1.Items.Add(li);
Bind_list(DropDownList1,dt, row[0].ToString(), grade1);
}
}
}
public static void Bind_list(DropDownList DropDownList1)
{
DropDownList1.Items.Clear();
string sql = "SELECT list_id,list_name,list_parent FROM list";
DataTable dt = DataBase.getDataTable(sql); //根据SQL语句获取DataTable值
Bind_list(DropDownList1,dt, "0", 0);
}
private static void Bind_list(DropDownList DropDownList1, DataTable dt, string parent, int grade)
{
DataRow[] dr = dt.Select("list_parent=" + parent, "list_id asc");
if (dr.Length > 0)
{
int grade1 = grade + 1;
foreach (DataRow row in dr)
{
ListItem li = new ListItem();
li.Text = "";
for (int i = 0; i < grade; i++)
{
li.Text += " ";
}
li.Text += "├" + row[1].ToString();
li.Value = row[0].ToString();
DropDownList1.Items.Add(li);
Bind_list(DropDownList1,dt, row[0].ToString(), grade1);
}
}
}