Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8038105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:07:37+00:00 2026-06-05T03:07:37+00:00

The following code is my rowdatabound event for my gridview. It works for everything

  • 0

The following code is my rowdatabound event for my gridview. It works for everything other than the cell text formatting as a currency. In fact the code line where i format the currency
causes the code to err. If i comment out the FormatCurrency line the code works fine. Why does that line a). not format the cell’s text and b). cause the error?

    Protected Sub gvDataRetrieval_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvDataRetrieval.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim dateindex As Integer = GetColumnIndexByHeaderText(gvDataRetrieval, "date")
        e.Row.Cells(dateindex).Text = Split(e.Row.Cells(dateindex).Text, " ")(0)
        For i As Integer = 0 To e.Row.Cells.Count - 1
            e.Row.Cells(i).Font.Size = 10
            e.Row.Cells(i).HorizontalAlign = HorizontalAlign.Center
            If i > dateindex Then
                If Convert.ToDecimal(e.Row.Cells(i).Text) < 0 Then
                    e.Row.Cells(i).ForeColor = Drawing.Color.Red
                Else
                    e.Row.Cells(i).ForeColor = Drawing.Color.Black
                End If
            End If
            e.Row.Cells(i).Text = FormatCurrency(e.Row.Cells(i).Text, 0)
        Next
    End If

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:07:39+00:00Added an answer on June 5, 2026 at 3:07 am

    As someone else said above, your code will error out if you attempt to format a non-numeric value as a currency and it seems to me that you are not doing that.

    Instead, if you want a particular column to be formatted as a currency, use the DataFormatString property of the column as so:

    <asp:BoundColumn DataField="YourCurrencyField" DataFormatString="{0:C}" />
    

    Obviously, you still need to make sure that your field is a valid number that can be formatted as a currency.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

following code works properly but it applies same cell text to all sections. How
Following code is a pretty simple and complete JQuery Dialog. Everything works. Problem is
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,
I have a gridview in an update panel with the following code to select
I have a GridView control in an asp.net 3.5 webpage, the following code executes
Following code works perfect and adds 1 and 2 values to the list, but
Following code: one click event (close login box) does not fire in Firefox (webkit-browser
Following code: $this->addElement('text', 'email', array( 'label' => 'Your email address:', )); $this->addElement('submit', 'submit', array(
Following code for passing an object to event handler is not working: $('a.another').live('click', function(e,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.