-2
下拉列表不顯示它應該顯示的項目! I HV是想顯示從文件夾中的圖像名稱的下拉列表中,但不這樣做! 啓動.aspx文件時我沒有錯誤! buuuuuut當我得到輸出只有空的下拉列表!下拉列表在C#中的問題
這個ManageProducts.aspx代碼:
名稱:
類型:
「的SelectCommand =」 SELECT * FROM [ProductTypes] ORDER BY [名稱]「>
價格:
圖片:
描述:
個
,這背後代碼:
using System;
using System.Collections;
using System.IO;
public partial class PagesNew_ManagementPages_ManageProducts : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack) //this baby makes the data not come every time the pg is refreshed ,
//postback=refresh page
GetImages();
}
private void GetImages()
{
try
{
//get all filepaths
string[] images = Directory.GetFiles(Server.MapPath("~/Img/Products/"));
//get all filenames and put them in a stupid array....yeah DSA days
ArrayList imageList = new ArrayList();
foreach (string image in images)
{
string imageName = image.Substring(image.LastIndexOf(@"\", StringComparison.Ordinal) + 1);
imageList.Add(imageName);
// see the Array in dd viwe datasource and refresh
ddImage.AppendDataBoundItems = true;
ddImage.DataBind();
}
}
catch (Exception e)
{
lblResult.Text = e.ToString();
}
}
protected void ddImage_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
爲什麼會出現在這裏的一個問題!!!! – Shosho 2015-01-09 23:13:51
可能您的下拉列表需要知道應該顯示哪些圖片。你不要設置它的DataSource – Steve 2015-01-09 23:17:30
@Steve你的意思是什麼? – Shosho 2015-01-09 23:23:26