2015-05-26 140 views
0

我有图像显示从一个文件夹和下面的功能的帮助下,我能够做到这一点。添加图像标题

private void LoadImages() 
{ 
    foreach (string strfile in Directory.GetFiles(Server.MapPath("~/Data"))) 
    { 
     ImageButton imageButton = new ImageButton(); 
     FileInfo fi = new FileInfo(strfile); 
     imageButton.ImageUrl = "~/Data/" + fi.Name; 
     imageButton.Height = Unit.Pixel(100); 
     imageButton.Style.Add("padding", "5px"); 
     imageButton.Width = Unit.Pixel(100); 
     imageButton.Click += new ImageClickEventHandler(imageButton_Click); 
     Panel1.Controls.Add(imageButton); 

    } 
} 

伙计们!我需要在图像下方显示图像的名称。请帮助!

+0

什么问题? – SLaks

+0

问题是我需要在其下面显示图像的名称。 – shaiToro

+0

如果ImageButton没有允许您执行此操作的属性,那么您只需使用HTML执行此操作...... –

回答

0

将ImageButton包装到具有文本标签的父DIV元素中。一个两行一格的小桌子也可以。

例子:

Table table = new Table(); 
TableRow row = new TableRow(); 
TableCell cell = new TableCell(); 
table.Controls.Add(row); 
row.Controls.Add(cell); 
cell.Controls.Add(imageButton); 
row = new TableRow(); 
cell = new TableCell(); 
table.Controls.Add(row); 
row.Controls.Add(cell); 
cell.Text = "Image Text"; 
+0

任何代码可能有帮助 – shaiToro

+0

什么是cell.Text =“图片文字”;应该在这里做? – shaiToro

+0

无论您将其定义为图像的名称。无论它是文件名还是其他一些元数据。 –