Question : Setting DataFormatString in Gridview programmatically

I'm trying to set the dataFormatString on a gridview based on a specific criteria.  I think I've found the solution except that it's skipping the first row for some reason.  Hoping there's something obvious I'm missing here.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Protected Sub gvForecast_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvForecast.RowDataBound
        Dim ea As GridViewRowEventArgs = TryCast(e, GridViewRowEventArgs)
        Dim iCount As Integer
 
        If ea.Row.RowType = DataControlRowType.DataRow Then
            Dim drv As DataRowView = TryCast(ea.Row.DataItem, DataRowView)
'only add it to percentage columns
            For iCount = 7 To 18
 
                Dim bf As BoundField = DirectCast(gvForecast.Columns(iCount), BoundField)
                If sViewType = "Percent" Then
                    bf.DataFormatString = "{0:P0}"
                Else
                    bf.DataFormatString = ""
                End If
            Next
        End If
    End Sub

Answer : Setting DataFormatString in Gridview programmatically

I figured it out, I needed to pull this check off:

If ea.Row.RowType = DataControlRowType.DataRow Then

I'm assuming this is because in the RowDataBound event the routine has already passed the header rows.  
Random Solutions  
 
programming4us programming4us