Damit ich mir das nicht mehr raussuchen hier eine Anleitung wie man eine Bilderpfad in der web.config speichert und in den ImageUrl-Parameter eines aspx:image-Tags einfügt:
Eintrag in der web.config:
<configuration>
<appSettings >
<addkey="ImagePath"value="~/Images/" />
</appSettings>
</configuration>
Eine allgemeine Methode zu auslesen der appSettings:
public static string GetAppSettings(string keyname)
{
string keyVal = ConfigurationManager.AppSettings.Get(keyname);
if (keyVal == null)
throw new System.Exception("AppSettings key '" + keyname + "' not exist.");
return keyVal;
}
Pfad in das aspx:image-Tag einfügen:
<asp:Image ID="Image2" runat="server" Width="120px" Height="130px"
ImageUrl='<%# this.GetImagePath(Eval("Bild")) %>' />
Die Methode “GetImagePath” in der codebehind-Datei:
protected string GetImagePath(object picture)
{
return Utils.GetAppSettings("ImagePath",true) + picture;
}