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();
}
}

Soft CornerRank #1,221 · 1.5K reputationPosted Mar 6, 2011, 11:29 PM EST
a solution made as per your code .. check this rar
Let me know if you have a problem :)
Madhu KRank #1,514 · 1.1K reputationPosted Mar 6, 2011, 11:51 PM EST
Make sure ListBox AutoPostback property is set to true. Use the debugger and check whether you are getting the imageurl in the for loop.
mevi dvash3 reputationPosted Mar 7, 2011, 1:46 AM EST
awesome!
Soft CornerRank #1,221 · 1.5K reputationPosted Mar 7, 2011, 2:24 AM EST