Public Function DatagridItemCount(ByVal dg As DataGrid) As Long
Dim NowPage As Integer = dg.CurrentPageIndex
dg.CurrentPageIndex = 0
dg.DataBind()
Dim page As Integer
Dim itemcount As Long = 0
For page = 0 To dg.PageCount - 1
dg.CurrentPageIndex = page
dg.DataBind()
itemcount = itemcount + dg.Items.Count
Next