今天用到一個下拉框綁定
要有層級關系顯示的
也很簡單
就當第一篇博客!
/// <summary>
/// 綁定下拉框
/// </summary>
/// <param name=
dt
>綁定的數據源</param>
/// <param name=
parentId
>上一級的id名稱</param>
/// <param name=
colId
>值名稱</param>
/// <param name=
colName
>文本名稱</param>
/// <param name=
drs
>最上層的記錄集合</param>
/// <param name=
ddl
>下拉框</param>
/// <param name=
leveStr
>層級的前綴</param>
/// <param name=
nextStr
>層級的前綴的前綴</param>
protected void GetChild(DataTable dt
string parentId
string colId
string colName
DataRow[] drs
DropDownList ddl
string leveStr
string nextStr)
{
foreach (DataRow dr in drs)
{
string txt = dr[colName]
ToString()
if (leveStr
Length !=
)
{
txt = leveStr + dr[colName]
ToString()
}
ddl
Items
Add(new ListItem(txt
dr[colId]
ToString()))
DataRow[] cdrs = dt
Select(parentId +
=
+ dr[colId] +
colId +
asc
)
if (cdrs
Length !=
)
{
string nextLevelStr = leveStr
Insert(
nextStr)
GetChild(dt
parentId
colId
colName
cdrs
ddl
nextLevelStr
nextStr)
}
}
}
drs通過dt
select(
條件
)查詢
From:http://tw.wingwit.com/Article/program/net/201311/13381.html