Posts
391
Comments
127
Trackbacks
0
January 2010 Entries
Dynamic Dummy Image Generator

Vor kurzem gefunden, eine Webseite welche einfache Dummy-Grafiken erstellt.

http://dummyimage.com/240x180, z.B. erstellt folgende Grafik:

240x180

posted @ Friday, January 15, 2010 4:01 PM | Feedback (0)
Generische Methode FindControlRecursive

Fürs Archiv eine generische Methode FindControlRecursive:

public static T FindControlRecursive<T>(Control parent, string id) where T : class
{
   foreach (Control child in parent.Controls)
   {
      if ((child.ID != null)
         && string.Equals(child.ID, id, StringComparison.InvariantCultureIgnoreCase)
         && (child is T))
         return (child as T);
 
      var ctl = FindControlRecursive<T>(child, id);
      if (ctl != null)
         return ctl;
   }
   return null;
}
posted @ Monday, January 11, 2010 1:26 PM | Feedback (0)
Bilderpfad in web.config / appSettings

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;
}
posted @ Wednesday, January 06, 2010 3:22 PM | Feedback (0)