您的位置:首页 > 运维架构

递归在Dropdownlist中显示树状结构

2008-06-10 18:24 344 查看
做项目的时候这种效果很多客户觉得挺好的,挺直观,但是实现呢有点技巧哈,有很多朋友问过我这个问题,今天我就把它贴出来哈:

效果图片:



下面是代码啦:
/// <summary>
/// 返回分类列表
/// </summary>
/// <param name="ParSql">查询条件</param>
/// <param name="LFlag">1为俄文,0为中文</param>
/// <returns></returns>
public DataTable GetType(string QueryStr, string LFlag)
{
DataTable table = COracle.GetTable("tbl_asset_type", "AMGUSER");
DataColumnCollection cols = table.Columns;
string SqlStr = "";
if (QueryStr != "" && QueryStr != null)
{
SqlStr = "select * from tbl_asset_type where " + QueryStr + " order by LBLJ,LBXH";
}
else
{
SqlStr = "select * from tbl_asset_type order by LBLJ, LBXH";
}
cols.Add("PDMMC", typeof(System.String));
Conn.Open();
OracleDataAdapter MyAdpter = new OracleDataAdapter(SqlStr, Conn);
MyAdpter.SelectCommand.ExecuteNonQuery();
MyAdpter.Fill(table);
OracleCommand Mycommand = new OracleCommand();
OracleDataReader Myreader;
for (int i = 0; i < table.Rows.Count; i++)
{
Mycommand.Connection = Conn;
Mycommand.CommandType = CommandType.Text;
Mycommand.CommandText = "select * from tbl_asset_type where bid in (" + table.Rows[i]["LBLJ"] + ") order by LBLJ , LBXH";
Myreader = Mycommand.ExecuteReader();
if (Myreader.HasRows)
{
while (Myreader.Read())
{
table.Rows[i]["PDMMC"] = table.Rows[i]["PDMMC"].ToString() + ">>";
if (LFlag == "1")
{
table.Rows[i]["PDMMC"] = table.Rows[i]["PDMMC"].ToString() + Myreader["DMMC_RU"].ToString();
}
else
{
table.Rows[i]["PDMMC"] = table.Rows[i]["PDMMC"].ToString() + Myreader["DMMC"].ToString();
}
}
}
Myreader.Close();
}
Conn.Close();
return table;
}
转自:http://hi.baidu.com/huqing7002/blog/item/fdd5b20a6124ab1d94ca6b2a.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: