Saturday, December 17, 2005 9:48:14 PM UTC :: Filed Under ASP.NET

The following is Fritz Onion’s posting on Complex data binding expressions in ASP.NET, converted into VB.NET:

I often find when using templated data-bound controls (in either ASP.NET 1.1 or 2.0) that my expressions become rather difficult to understand because of the need to fit all of your logic into a single expression. For example, I have seen databound expressions that look something like:

<asp:TemplateField HeaderText="SomeColumn">
  <
ItemTemplate>
    <%# ((bool)Eval("foo")) ? Eval("bar") : (((bool)Eval("quux")) ? Eval("a") : Eval("b")) %>
  </ItemTemplate>
</
asp:TemplateField>

Which is even worse in 1.1 because each Eval must be replaced with DataBinder.Eval(Container.DataItem, "xx"). There are also occasions where you just can't compress all the logic you need to into a single expression. An alternative, which I find myself using quite a bit, even when developing in 2.0, is to write a single method in your code behind class to generate the desired string. Have it take an object reference (which will be the bound row) and take as many lines as you like to construct the string to be generated in the template. Here's a method that returns the same string as the overly-complex expression above:

Protected Function GenerateFooString(ByVal dataItem As ObjectAs String
    Dim 
foo As Boolean = CType(DataBinder.Eval(dataItem, "foo"),Boolean)
    
Dim quux As Boolean = CType(DataBinder.Eval(dataItem, "quux"),Boolean)
    
Dim ret As String = string.Empty
    
If foo Then
        
ret = CType(DataBinder.Eval(dataItem, "bar"),String)
    
ElseIf quux Then
        
ret = CType(DataBinder.Eval(dataItem, "a"),String)
    
Else
        
ret = CType(DataBinder.Eval(dataItem, "b"),String)
    
End If
    Return 
ret
End Function

And the simplified template now looks like:

 <asp:TemplateField HeaderText="SomeColumn">
  <
ItemTemplate>
    <%# GenerateFooString(Container.DataItem) %>
  </ItemTemplate>
</
asp:TemplateField>

Once again, this is not my code or idea; it all belongs to Fritz Onion!

Saturday, December 17, 2005 9:37:49 PM UTC :: Filed Under ASP.NET

I haven’t quite figured-out what this plugin does, but it sounds like something I should use since I’m trying to work with standards compliant CSS files in my latest web apps:

CSS Properties Window Plugin

Wednesday, December 14, 2005 3:08:04 PM UTC :: Filed Under Web Design

After dabbling with XHTML and extensive CSS a few months ago, I finally ‘saw the light’ as to why some web designers make such extensive use of CSS and DIV tags over traditional HTML and tables.  However, for as many cool things you can do with CSS and DIV tags, there are drawbacks… like trying to make a simple 2 or 3 column web page ;-S

On the surface, it seems like an easy task to create a multi-column CSS layout, but the problem sets-in when you try to view your site in different browsers.  At the moment, it seems like no two browsers will display content the same even though many of them are trying to adhere to the W3C’s standards. As a result, most of the multi-column designs I’ve seen have all sorts of “CSS hacks” to fudge the layout in various browsers.

Anyway, to aid in creating a multi-column CSS design, give this template generator a try:

CSS Source Ordered Variable Border 1-3 Columned Page Maker

Using the generator is a little easier than trying to reverse engineer someone else’s design that doesn’t quite fit what you want to do.

Wednesday, December 14, 2005 2:53:37 PM UTC :: Filed Under ASP.NET

Seems that most programmers are not good designers, and most designers are not good programmers.  However, Microsoft is making it easier for programmers to not worry so much about design by providing a set of new templates for VisualStudio.NET 2005.

The interesting part is that these templates are not only pretty nice looking, some of them conform to the XHTML 1.1 Strict standard; that’s something you couldn’t even dream of doing with VisualStudio.NET 2003!

In addition to being standards compliant, these templates make use of Master Pages, Themes, and Skins, so they should serve as good references on how to properly use these new features in VS.NET 2005.

MSDN: Design Templates

Wednesday, December 14, 2005 2:45:59 PM UTC :: Filed Under Photography

Converting a color photo to black and white is pretty easy, but going the other way is not… until now!  Recolored.com has a free beta download that allows just about anyone to colorize their black and white photos:

http://www.recolored.com/

Thursday, December 08, 2005 5:17:30 PM UTC :: Filed Under ASP.NET

What? You don’t have any Microsoft certifications and you feel lonely?  Not to worry, Jason Mauss has created some new Microsoft MVP awards that you can add to your web site so that you’ll fit-in better ;-)

            
  
            

Navigation
On this page....
Search
Archives
<December 2005>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Categories
Contact me
Send mail to the author(s) Contact Todd M. Taylor