Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey!
i have a directory that have some picture ...
well i have a slide show that can find images and add them to my slideshow as imagebutton !
well when user click on one of them i want slideshow show it!
my problem is this that i cant know what imagebutton clicked to show it!
this is my code:
C#
//initialize the slideshow
            string[] strImageAdress;
            string[] HomeSlideShowImages = System.IO.Directory.GetFiles(@"D:\DSource\DSource\Site\FirstPattern\Dios\Dios\Images\ImagesHome");
            foreach (string hssi in HomeSlideShowImages)
            {
                strImageAdress = hssi.Split('\\');
                foreach (string strDirectories in strImageAdress)
                {
                    if (strDirectories.Contains('.'))
                    {
                        imgbtnSlideShowPic = new ImageButton();
                        imgbtnSlideShowPic.AlternateText = @"..\Images\ImagesHome\" + strDirectories;
                        imgbtnSlideShowPic.Height = 50;
                        imgbtnSlideShowPic.Width = 50;
                        imgbtnSlideShowPic.ImageUrl = @"..\Images\ImagesHome\" + strDirectories;
                        pnlSlideShowController.Controls.Add(imgbtnSlideShowPic);

                    imgbtnSlideShowPic.Click += new  ImageClickEventHandler(imgbtnSlideShowPic_Click);                     
                    }
                }
            }


how can i know which imagebutton clicked ? wich event? please help
Posted
Comments
[no name] 4-Aug-12 15:58pm    
"wich event"... how about imgbtnSlideShowPic_Click?

I would recommend you to set ID while generating the ImageButton. Try this:
C#
int count = 0;
foreach (string strDirectories in strImageAdress)
{
    if (strDirectories.Contains('.'))
    {
        count ++; //Increase you count by one
        imgbtnSlideShowPic = new ImageButton();
        imgbtnSlideShowPic.AlternateText = @"..\Images\ImagesHome\" + strDirectories;
        imgbtnSlideShowPic.ID = "imgbtn"+count.ToString();
        //Here we have given ID to the button.
        imgbtnSlideShowPic.Height = 50;
        imgbtnSlideShowPic.Width = 50;
        imgbtnSlideShowPic.ImageUrl = @"..\Images\ImagesHome\" + strDirectories;
        pnlSlideShowController.Controls.Add(imgbtnSlideShowPic);

    imgbtnSlideShowPic.Click += new  ImageClickEventHandler(imgbtnSlideShowPic_Click);                     
    }
}
protected void imgbtnSlideShowPic_Click(object sender, EventArgs e)
{
    ImageButton img = (ImageButton)sender;
    string btn = img.ID;
    //write your code here
}




--Amit
 
Share this answer
 
Comments
ali_heidari_ 5-Aug-12 5:55am    
i used this way by myself ... thank you for spending time!
Try:
C#
protected void imgbtnSlideShowPic_Click(object sender, EventArgs e)
{
    ImageButton ib = (ImageButton)sender;
    string objSenderID = ib.ID;
    // you know the ID of the image button clicked!
    // Use the way you like!
}
 
Share this answer
 
Comments
ali_heidari_ 4-Aug-12 19:57pm    
you are right... but as you see on my codes, i didnt choose id for my imagebuttons, they initialized by a foreach! they dont have ID...
Sandeep Mewara 5-Aug-12 1:38am    
You should. Go define one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900