您訪問Value
財產之前,我無法從我的下拉框中得到比一個空值以外的其他,我嘗試將文件上傳到不同的目錄...DropDownList1.SelectedValue爲空?
public class dropDownInfo
{
public string pathName { get; set; }
public string pathValue { get; set; }
}
string uploadFolder = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// reference to directory
//DirectoryInfo di = new DirectoryInfo("//DOCSD9F1/TECHDOCS/");
DirectoryInfo di = new DirectoryInfo("D:/SMGUpload/SMGUpload/files/");
// create list of directories
List<dropDownInfo> DropDownList = new List<dropDownInfo>();
foreach (DirectoryInfo i in di.GetDirectories())
{
dropDownInfo ddInfo = new dropDownInfo();
ddInfo.pathName = i.FullName;
ddInfo.pathValue = i.FullName;
DropDownList.Add(ddInfo);
}
DropDownList1.DataSource = DropDownList;
DropDownList1.DataTextField = "pathName";
DropDownList1.DataValueField = "pathValue";
DropDownList1.DataBind();
}
}
protected void DropDownList1_IndexChanged(object sender, EventArgs e)
{
uploadFolder = DropDownList1.SelectedItem.Value;
}
protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
{
if (e.IsValid)
{
string uploadDirectory = Server.MapPath("~/files/");
//string uploadDirectory = @"\\DOCSD9F1\TECHDOCS\";
string fileName = e.UploadedFile.FileName;
//string uploadFolder = DropDownList1.SelectedValue;
//string path = (uploadDirectory + uploadFolder + "/" + fileName);
string path = Path.Combine(Path.Combine(uploadDirectory, uploadFolder), fileName);
e.UploadedFile.SaveAs(path);
e.CallbackData = fileName;
}
}
並使用dropdownlist1.selecteditem.value;給了我一個參考例外。 – bluetickk 2011-06-08 17:13:42
@bluetickk你可以嘗試DropDownList1.SelectedValue嗎? – thomasvdb 2011-06-08 17:38:03
同樣的事情,它仍然是null – bluetickk 2011-06-08 17:53:03