Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2007, 01:45 PM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default conditional formatting on databound repeater

This is in ASP.NET 1.1. I have a repeater. I am handling the ItemDataBound event for that repeater. I want to implement conditional formatting. After trying a couple of things that doesn't work, I found this MSDN article that does allow me to manipulate the actual data value that is displayed but I remain unable to format the string using {0:N} or {0:P}, etc.

Here is the ItemDataBound event handler:



Protected Sub rptrCustomReport_OnItemDataBound(ByVal source As Object, ByVal e As RepeaterItemEventArgs) Handles rptrCustomReport.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or _
            e.Item.ItemType = ListItemType.AlternatingItem Then

            Dim dbr As DbDataRecord = CType(e.Item.DataItem, DbDataRecord)
            If Not IsDBNull(dbr("CurrentYearUnits")) AndAlso dbr("CurrentYearUnits") <> "ND" Then
                String.Format("{0:n}", CType(e.Item.FindControl("lblCyu"), Label).Text)
            End If
End If
    End Sub

Any help you can offer is greatly appreciated as always!
 
Old April 25th, 2007, 04:58 PM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I figured out my problem, which was related to String.Format() not to conditional formatting or handling the OnItemDataBound event in the repeater.

It seems the String.Format() method requires that you cast your argument that you want to format:

String.Format("{0:0,0}", Convert.ToInt32(myString))

This is about the dumbest way I can imagine to implement the Format method. I don't know why the hell it doesn't just cast whatever object you pass in to a string, try to apply to format, and if it is successful return the formatted string, else throw an error. This is how you would intuitively expect it to work!

As an aside, here is the link to how to do conditional formatting to a databound repeater:

http://support.microsoft.com/kb/317582





Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional formatting jeremy1048 Access 4 July 3rd, 2008 11:20 AM
Conditional formatting vemaju Excel VBA 2 June 6th, 2007 04:41 AM
Conditional Formatting on Subform echovue Access 4 March 3rd, 2006 03:25 AM
Conditional Formatting Corey Access 1 November 8th, 2005 12:18 AM
Conditional Formatting... In Access??? lguzman Access VBA 2 September 23rd, 2004 03:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.