当前位置: 代码迷 >> ASP >> asp.net实现树形上拉列表
  详细解决方案

asp.net实现树形上拉列表

热度:125   发布时间:2012-09-01 09:33:03.0
asp.net实现树形下拉列表
<select name="newsclass" id="newsclass" >
<%this.ResponseTypeTree(); %>
</select>
public void ResponseTypeTree()
{

string sel = "";
DataSet ds = new DataSet();
ds = xjdata.GetNewsTypeDataSetByParentID("0");
dv = xjdata.GetNewsTypeDataSetByParentID().Tables[0].DefaultView;


Response.Write("<option value=0 selected>选择类别</option>");



for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Response.Write("<option value=" + ds.Tables[0].Rows[i]["id"].ToString() + ">├" + ds.Tables[0].Rows[i]["name"].ToString() + "</option>");
this.GetChildType(ds.Tables[0].Rows[i]["id"].ToString(), "");
if (str != "")
{
Response.Write(str);
str = "";
}
}
if (str != "")
{
Response.Write(str);
}

}
private void GetChildType(string parentcode, string str1)
{
dv.RowFilter = "parentid='" + parentcode + "'";
dv.Sort = "orderid asc";
int a = dv.Count;
string imgstr = "";
string sel = "";
imgstr = str1 + "?";
//if (dv.Count > 0)
//{
// imgsrt = "<img src="images/folderHR.gif" mce_src="images/folderHR.gif" width=18 height=18>";
//}
if (dv.Count == 0)
return;
for (int i = 0; i < a; i++)
{

str += "<option value=" + dv[i]["id"].ToString() + " >│" + imgstr + "└" + dv[i]["name"].ToString() + "</option> ";
this.GetChildType(dv[i]["id"].ToString(), imgstr);
dv.RowFilter = "parentid='" + parentcode + "'";
dv.Sort = "orderid asc";
}
}

?

  相关解决方案