hello i have this problem i have a listbox and i bind it to an image folder
i want to display the image when a user is selecting item from the box
but no matter what i do it wont display the picture here is the code :
public partial class EditPhotos : System.Web.UI.Page
{
Int32 cnt, i;
protected void Page_Load(object sender, EventArgs e)
{
ListImages();
}
protected void btnfind_Click(object sender, EventArgs e)
{
}
protected void btndel_Click(object sender, EventArgs e)
{
string Dir = "~/images/fullscreen/";
foreach (ListItem li in ListBox1.Items)
{
if (li.Selected)
{
File.Delete(Server.MapPath(Dir + li.Text));
}
}
lblerror.Text = "Selected files deleted successfully.";
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
cnt = ListBox1.Items.Count; // count the items in listbox
for (i = 0; i <= cnt - 1; i++)
{
if (ListBox1.Items[i].Selected == true)
{
// Will display the selected image
Image1.ImageUrl = ListBox1.Items[i].Text;
}
}
}
private void ListImages()
{
DirectoryInfo dir = new DirectoryInfo(MapPath("~/images/fullscreen/"));
FileInfo[] file = dir.GetFiles();
ArrayList list = new ArrayList();
foreach (FileInfo file2 in file)
{
if (file2.Extension == ".jpg" || file2.Extension == ".jpeg" || file2.Extension == ".gif")
{
list.Add(file2);
}
}
ListBox1.DataSource = list;
ListBox1.DataBind();
//DataList1.DataSource = list;
//DataList1.DataBind();
}
}