troubleshooting Question

Setting DataFormatString in Gridview programmatically

Avatar of stretch73
stretch73Flag for United States of America asked on
.NET ProgrammingASP.NETVisual Basic.NET
10 Comments1 Solution1947 ViewsLast Modified:
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.
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}"
                    bf.DataFormatString = ""
                End If
        End If
    End Sub

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros