我有一个下拉列表我&页面上想要的列表项是从Web服务器上的本地目录文件夹...即....asp:DropDownList从本地目录抓取数据?
T:\窗体 T:\手册 ŧ :\ SOFTWARE
这是到目前为止我的代码...
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("C:/");
DirectoryInfo[] dirArray = di.GetDirectories();
DropDownList1.DataSource = dirArray;
foreach (DirectoryInfo i in dirArray)
{
DropDownList1.DataTextField = i.FullName;
DropDownList1.DataValueField = i.FullName;
}
}
解决
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("C:/");
DropDownList1.DataSource = di.GetDirectories();
DropDownList1.DataBind();
foreach (DirectoryInfo i in di.GetDirectories())
{
DropDownList1.DataTextField = i.FullName;
}
}
太感谢你了,我怎么拿到数值F从一个数组到现在的下拉列表? – bluetickk 2011-06-07 14:30:17
您可以将阵列直接绑定到下拉列表。例如:dropDownList.DataSource = yourFileArray;然后设置DataTextField和DataValueField并调用数据绑定。 – WraithNath 2011-06-07 14:31:39
你还需要帮助吗? DataTextField和DataValue字段应该是作为字符串传递的属性的名称,而不是对象的实际值。例如“FullName”而不是i.FullName – WraithNath 2011-06-07 15:41:30