Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

GridView1 format performance problem

$
0
0

Before Exporting right format from GridView to Excel, I need to format GridView using GridView1_RowDataBound.

But, doing so will affact performace. (about 10 time slow)

Is there another way to format them? (e.g. keep "0" in first character in [Member ID] column/display date only in datetime column)

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim mydate As DateTime
Dim myRow As GridViewRow = e.Row
Dim i As Integer = 0

Do While i < myRow.Cells.Count
Try
e.Row.Cells(CInt(Session("MEMBIDINDEX"))).Attributes.Add("class", "text") 'keep "0" in first character MEMBID 7801288->07801288
' Is the cell a date?
mydate = DateTime.Parse(myRow.Cells(i).Text.ToString())
If mydate <> "01/01/1900" Then
myRow.Cells(i).Text = mydate.ToShortDateString() 'DateTime->Date only
Else
myRow.Cells(i).Text = ""
End If
Catch
' not a date, move on
End Try
i += 1
Loop
End Sub


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>