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 8007453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:49:47+00:00 2026-06-04T17:49:47+00:00

I have a gridview which has three columns date, pnl, cumpnl I am able

  • 0

I have a gridview which has three columns date, pnl, cumpnl
I am able to add some formatting when applied to all cells using code such as

Protected Sub OnRowCreated(sender As Object, e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        For Each cell As TableCell In e.Row.Cells
            cell.Font.Size = 10
            cell.HorizontalAlign = HorizontalAlign.Center
        Next
    End If

End Sub

Within that For…Next loop how can I reference only the cells in the pnl and cumpnl columns? I don’t see anyway to reference cells by the columnheader name or index.

Update:

by Using a RowDataBound event I can now reset the format of the values in the columns but the setting of the forecolor based on the cells value keeps erring (“Input string not in correct format”). Also, I am hardcoding the the column indexes. I need a way to dynamically get the column index based on the column header name

Protected Sub gvDataRetrieval_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDataRetrieval.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        For i As Integer = 1 To 2
            e.Row.Cells(i).Text = FormatCurrency(e.Row.Cells(i).Text, 2).ToString()
            If Double.Parse(e.Row.Cells(i).Text) < 0 Then e.Row.Cells(i).ForeColor = Drawing.Color.Red
        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-04T17:49:49+00:00Added an answer on June 4, 2026 at 5:49 pm

    Outside for each loop:

    e.Row.Cells(index)
    

    Eg.
    For adding header tooltip:

        Protected Sub Grid1_RowCreated(ByVal sender As Object, ByVal e As GridRowEventArgs)
           //setting row cells
        If e.Row.RowType = DataControlRowType.DataRow Then
          For i As Integer = 1 To e.Row.Cells.Count
            If i = 1 Then
               e.Row.Cells(i).Font.Size= 8
            ELSE
               e.Row.Cells(i).Font.Size= 12
            END IF
          NEXT
        End If
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have made a gridview which has many columns and the editmode , some
I have a gridview which displays rows and columns all linked to an sql
I have gridview which has columns of data and a button below the Apply
For example, Lets say that I have a gridview column which has important controls,
I have a GridView in which each row has a custom view. The grid
I have a GridView on a .aspx page with a hidden column which has
ok i have a project which has many gridview in its pages... now i
I have a gridview within an updatepanel which allows paging and has a linkbutton
I have a GridView which has following template field that holds the filename, when
I have a database which has some table and every one of them has

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.