如何使用来自不同文件夹的 Eval 将图像绑定到图像控件?

how to binding images to image control with Eval from defferent folders?

我有如下代码:

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# "../Image/Products/1/" + Eval("P_Pic")   %>' />

这是为了从文件夹中读取图像地址。imageButton 控件在 listview 中,并且数据来自多个 table 并且图像驻留在不同的文件夹中......这意味着这部分代码:“。 ./Image/Products/1/" 每个 table.can 应该不同 你帮我处理这个吗?谢谢注意:每个 table 是针对不同的产品,此代码是因为合并所有产品以显示

我找到了处理这个问题的方法

public string GetImage(object P_Pic )
    {
        if (P_Pic != null & ProductCategory == "a")
        {
            string Pic = "../Image/Products/a/" + P_Pic;
            //do something with the ImageID to return the image path as string
            return Pic;
        }
        else if (P_Pic != null & ProductCategory == "b")
        {
            string Pic = "../Image/Products/b/" + P_Pic;
            return Pic;
        }
        else if (P_Pic != null & ProductCategory == "c")
        {
            string Pic = "../Image/Products/c/" + P_Pic;
            return Pic;
        }
        else if (P_Pic != null & ProductCategory == "d")
        {
            string Pic = "../Image/Products/d/" + P_Pic;
            return Pic;
        }
        else if (P_Pic != null & ProductCategory == "e")
        {
            string Pic = "../Image/Products/e/" + P_Pic;
            return Pic;
        }
        else if (P_Pic != null & ProductCategory == "f")
        {
            string Pic = "../Image/Products/f/" + P_Pic;
            return Pic;
        }
        else
        {
            return "";
        }
    }

其中 "ProductCategory" 是通过 here.next 控制的会话 我添加了这段代码:

<img id="img" class="img" runat="server" src='<%# GetImage(Eval("P_Pic")) %>' />

仅此而已:)