添加图像标题

时间:2015-05-26 17:51:40

标签: c# asp.net

我有从文件夹显示的图像,并且在下面的功能的帮助下,我能够做到这一点。

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);

    }
}

专家!我需要在图像下方显示图像的名称。请帮忙!

1 个答案:

答案 0 :(得分: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";