求高手指点 ASP.NET ----ListBox控件问题??
求高手指点 ASP.NET ----ListBox控件问题??
在ListBox控件中怎么获取选种行?
ListBox1.SelectedItem.Text;获取不到值,为什么?
<asp:ListBox ID= "ListBox1 " runat= "server " Height= "344px "
OnSelectedIndexChanged= "ListBox1_SelectedIndexChanged "
Width= "409px "> </asp:ListBox>
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string dir = @ "G:\PHOTO ";
ListBox1.DataSource = ListFiles(new DirectoryInfo(dir));
ListBox1.DataBind();
}
public Array ListFiles(DirectoryInfo dir)
{
if (!dir.Exists)
return null;
if (dir == null)
return null;
FileSystemInfo[] files = dir.GetFileSystemInfos();
ArrayList al = new ArrayList();
for (int i = 0; i < files.Length; i++)
{
FileInfo file = files[i] as FileInfo;
if (file != null && file.Extension == ".jpg ")
{
al.Add(file.FullName.Substring(file.FullName.LastIndexOf(@ "\ ") + 1));
}
}
Array a = al.ToArray();
Array.Sort(a);
Array.Reverse(a);
return a;
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs &n