使用C#代码隐藏在ASP.NET中创建和操作ImageButtons数组 [英] Creating and manipulating an array of ImageButtons in ASP.NET with C# codebehind

查看:51
本文介绍了使用C#代码隐藏在ASP.NET中创建和操作ImageButtons数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在一个网站上工作,我想创建一个胆汁页面。因此,根据图像的数量,如果我可以执行以下操作,则会自动更新。



图像正在添加到数据库中UploadImage页面。所以我的数据库中包含他们的工具提示,类别和图像。在.cs fuke中,我想创建一个具有所有功能的ImageButtons动态数组,例如: ImageUrl,Tooltip,OnClientClick等。



如果有人帮助我,我会很感激。不管怎么说,还是要谢谢你。答案越早,它就越好。

Hi to everyone. I am working on a website and I want to create a gallry page. So according to the number of images, the gallry will be updated automatically if I can do the following.

The images are being added to database with an UploadImage page. So I have all my images in my database with their tooltips, categories, and imageurls. The in the .cs fuke I want to create a dynamic array of ImageButtons with their all features, e.g. ImageUrl, Tooltip, OnClientClick, etc.

If anyone helps me I will appreciate that. Thanks anyway. The sooner comes the answer, it gets better.

推荐答案

你好Cengiz,



这是一个基本的例子使用Code-Behind动态创建ImageButton:

Hi Cengiz,

Here's a basic example for dynamic creation of an ImageButton using Code-Behind:
private void RenderImageButtons()
{
    ImageButton img = new ImageButton();
    img.ID = "img";
    img.AlternateText = "ImageButton";
    //img.Click += new ImageClickEventHandler(img_Click);
    img.Command +=new CommandEventHandler(img_Command);
    img.CommandName = "select";
    img.CommandArgument = "~/ConcertTickets.aspx";
    img.Width = Unit.Percentage(100.00);
    this.Page.Controls.Add(img);
}





你可以处理一个数组,给每个ImageButton它的ID,这样你就可以访问它并关联对它,或处理它的属性等





干杯,

Edo



You can handle an array of course, give each ImageButton it's ID so that you can then access it and relate to it, or handle it's properties etc.


Cheers,
Edo


ImageButton [] image = new ImageButton [25];

for(int i = 0; i< 5; i ++)

{

image [i] = new ImageButton();

image [i] .Height = 100;

image [i] .Width = 75;

image [i] .BorderWidth = 0;

image [i] .ImageUrl =〜/ Images / Danger.png;

image [i] .Visible = true;

form1.Controls.Add(image [i]);

form1.Controls.Add(new LiteralControl(
< br>));

}
ImageButton[] image = new ImageButton[25];
for (int i = 0; i < 5; i++)
{
image[i] = new ImageButton();
image[i].Height = 100;
image[i].Width = 75;
image[i].BorderWidth = 0;
image[i].ImageUrl = "~/Images/Danger.png";
image[i].Visible = true;
form1.Controls.Add(image[i]);
form1.Controls.Add(new LiteralControl("

"));
}


这篇关于使用C#代码隐藏在ASP.NET中创建和操作ImageButtons数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆