>
 Monday, August 22, 2005
« ASP.NET 2.0 Data Binding Tips - How to a... | Main | PDC is in LA...and cool stuff is going o... »

If you haven't tried this already, I have definitely saved you at least one hour, for the two I spent playing, toying, testing, and writing this little blog. The issue is when you want to combine formatting statements with binding activity. Of course the trusty Eval() function will allow us to provide a format statement:

<asp:Image id=Image2 width=200 height=200 BorderWidth=2 runat="server" ImageUrl='<%# Eval("url", "~/Photos/{0}") %>' ></asp:Image>

But what if I don't want to hard-code the path? What if I want to use AppSettings, for example? It really isn't so difficult, but it required a little playing around before I realized that I can literally use the binding statement for any code output, including the String.Format...and, within the context of the binding statement <%# ... %> I can use Container.DataItem to get at row values. This example pulls together AppSettings with row values to build the ImageUrl property:

<asp:Image id=Image2 width=200 height=200 BorderWidth=2 runat="server" ImageUrl='<%# String.Format("{0}{1}", System.Configuration.ConfigurationManager.AppSettings["PhotosDir"], ((System.Data.DataRowView)Container.DataItem)["url"])%>' ></asp:Image>

 

8/22/2005 9:15 PM ADO.NET | ASP.NET | ASP.NET 2.0 Migration  | Comments [5]  |  View reactions  |  Trackback
    ON THIS PAGE
    SEARCH
    CATEGORIES
    ARCHIVES
    BLOGROLL

Designed by NUKEATION STUDIOS