Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 June 10th, 2008, 01:26 PM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default Question about formatting

I'm using a 3rd-party component for a shopping cart (dotnetCART), and I am having a problem formatting a string. I know that since this is a 3rd-party control, you all may not be able to help, but I thought I's ask anyways...

The dotnetCART component has a web control called "Display Catalog" which displays products from the database. Although fields such as "Price" and "Weight" are included in the web control, my "WholePrice" field is not, and so I have to pull it in using the "GetCustom" property (or is it called a method?).

Right now the code in question looks like this:

Code:
<dotnetCART:DisplayCatalog>

    ...code...

    <ItemDetailsTemplate>
        <asp:Label 
            ID="lblWholesalePrice" 
            runat="server"
            Text='<%#Container.GetCustom("WholePrice") %>'>
        </asp:Label>

    </ItemDetailsTemplate>
</dotnetCART:DisplayCatalog>

(FYI, a non-custom field would have been written into the label as "<%#Container.Price%>")

The above label works OK, but it displays the data without formatting, and so my "WholePrice" appears as "12.55" or "6.554", not "$6.55". I've read the asp.net information on formatting strings, and I have tried to apply a similar formatting syntax to the "Container.GetCustom" without success. I have tried:

Code:
Text='<%#Container.GetCustom(FormatCurrency("WholePrice")) %>'>
...returns an error from the component: "Conversion from string "WholePrice" to type 'Double' is not valid."

Code:
Text='<%#Container.GetCustom("WholePrice","{0:c}") %>'
...returns "BC30057: Too many arguments to 'Public Function GetCustom(strField As String) As String'."

Code:
Text='<%# DataBinder.Eval(Container.GetCustom, "WholePrice", "{0:c}")%> '>
...returns "BC30455: Argument not specified for parameter 'strField' of 'Public Function GetCustom(strField As String) As String'."

and

Code:
Text='<%# String.Format("{0:c}", Container.GetCustom("WholePrice")) %>'
... does not have any effect, but displays the unformatted "WholePrice".

Once again, I realize no one may be able to help in this case, but thank you for any advice or suggestions. The 3rd-party documentation seems a little fuzzy on this subject to my novice eyes, but the relevent passages appear to be as follows:

Quote:
quote:
Display Catalog Properties:
CategoryCustomFields: List of fields from categories table that you want to show in the template using the GetCustom property.
CategoryCustomFields = "Created"
Catalog Template Properties / Containers:
GetCustom("FieldName"): Used to show custom field data in the Templates. This returns any custom field data.

Programmatically changing a control value within a given page:
This is useful if you wish to change a control within the template programmatically, for example for language customization.

Label myTemp = (Label) Page.FindControl("Catalog:ItemDetails:myWeight");
if(myTemp != null);
myTemp.Text="Weight(Test):";

The "Catalog:ItemDetails:myWeight" is the ID for Weight label control used in default.aspx. The "Catalog" is the ID control in default.aspx page for Catalog control and "ItemDetails" is hardcoded ID inside the component for ItemDetailsTemplate Template. "myWeight" is the ID for label inside the ItemDetailsTemplate Template in default.aspx page
Thanks again.

 
Old June 10th, 2008, 01:42 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Would this work:

Text='<%#FormatCurrency(Container.GetCustom("Whole Price")) %>'>

E.g. pass the result from GetCustom into the FormatCurrency method? Depending on what GetCustom returns, you may need ToString:

Text='<%#FormatCurrency(Container.GetCustom("Whole Price").ToString()) %>'>

Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old June 10th, 2008, 02:02 PM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default

That first one did it, thank you!

Now I must read up on the FormatCurrency method to understand what just happened...

Thanks again.


 
Old June 10th, 2008, 04:14 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It's a matter of order. With this code:

Container.GetCustom(FormatCurrency("WholePrice"))

you feed the literal string WholePrice into FormatCurrency which of course won't work. Even if it would, you would feed something like $WholePrice into GetCustom which doesn't make sense either.

By reversing things:

FormatCurrency(Container.GetCustom("WholePrice"))

you first get the amount from GetCustom:

Container.GetCustom("WholePrice")

which could result in something like 40 which you then feed to FormatCurrency which changes 40 into $40.00

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Question in the BugBase mikener BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 June 6th, 2008 01:45 PM
Access Report Formatting Question arbalest Access 1 December 3rd, 2004 11:15 AM
text formatting question dadoonan BOOK: Beginning ASP 3.0 1 November 15th, 2004 02:12 AM
stupid table formatting question badgolfer ASP.NET 1.0 and 1.1 Basics 1 July 20th, 2004 07:47 AM
Beginner - Datagrid formatting question badgolfer VB.NET 2002/2003 Basics 1 November 18th, 2003 01:15 PM





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