TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mevi dvash
NA
3
0
listbox display images when item is selected
Mar 7 2011 3:48 AM
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();
}
}
Reply
Answers (
4
)
Change GridView cell color
how to get text of dropdownlist of gridview