求助 关于DropDownList的初始化
我在前台放了一个DropDownList控件,想要页面首次加载时,显示/,用于根目录
在后台用这段代码来实现,但是得不到结果,页面首次加载时,显示空,里面什么也没有,
注意:/不是存储在数据库中。
后台代码:
在后台用这段代码来实现,但是得不到结果,页面首次加载时,显示空,里面什么也没有,
注意:/不是存储在数据库中。
后台代码:
public void ShowDirectory(DropDownList dirList, int nParentID)
{
DataTable dataTable = SystemTools.ConvertDataReaderToDataTable(GetDirectorys());
dirList.Items.Clear();
DataRow[] rowList = dataTable.Select("ParentID='-1'");
if (rowList.Length <= 0) return;
//创建、添加新节点
dirList.Items.Add(new ListItem("/", rowList[0]["DirID"].ToString()));
//创建其他节点
CreateChildNode(dirList, dataTable, Int32.Parse(rowList[0]["DirID"].ToString()), "/");
}
public void CreateChildNode(DropDownList dirList, DataTable dataTable, int nParentID, string sParentName)
{
DataRow[] rowList = dataTable.Select("ParentID='" + nParentID.ToString() + "'", "CreateDate DESC");
foreach (DataRow row in rowList)
{
string sName = sParentName + row["Name"].ToString() + "/";
//创建新节点
dirList.Items.Add(new ListItem(sName, row["DirID"].ToString()));
//递归调用,创建其他节点
CreateChildNode(dirList, dataTable, Int32.Parse(row["DirID"].ToString()), sName);
}
}
...全文
相关推荐
asp.net中DropDownList控件的二级联动
asp.net(C#)中DropDownList控件的二级联动,两种方法,第一种为普通方法,第二种为从数据库绑定DropDownList的。
DropDownList操作
DropDownList操作
dropdownlist三级联动效果
dropdownlist三级联动效果,function drop1() { while(document.all["DropDownList2"].options.length>1) document.all["DropDownList2"].options.remove(1);
C#中DropDownList动态生成的方法
主要介绍了C#中DropDownList动态生成的方法,实例分析了C#中DropDownList的使用技巧,非常具有实用价值,需要的朋友可以参考下
Dropdownlist
Dropdownlist 例子 可以参考一下


