找到点击的图像按钮 [英] find clicked imagebutton
本文介绍了找到点击的图像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿!
我的目录中有一些图片...
好吧,我有一个幻灯片可以找到图像并将其作为imagebutton添加到我的幻灯片中!
很好,当用户单击其中之一时,我希望幻灯片显示它!
我的问题是我不知道单击了哪个imagebutton来显示它!
这是我的代码:
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:
//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
推荐答案
我建议您在生成ImageButton时设置ID.试试这个:
I would recommend you to set ID while generating the ImageButton. Try this:
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
--Amit
尝试:
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!
}
这篇关于找到点击的图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文