ok, here is my code

vb Code:
  1. Dim sqlstr As String
  2.         sqlstr = "select * from trackmain where " + pwhereClause + "ORDER BY datee DESC"
  3.         Dim dt As DataTable
  4.         Dim datatable1 As DataTable
  5.  
  6.         Dim command As New DbCommand(sqlstr, CommandType.Text, Nothing)
  7.  
  8.  
  9.         datatable1 = command.ExecuteDataTable()
  10.  
  11.  
  12.         dt = GetCustDT()
  13.         If (datatable1.Rows.Count > 0) Then
  14.  
  15.  
  16.             Dim str As String()
  17.  
  18.             str = (datatable1.Rows.Count / _rowCount).ToString().Split(".")
  19.             If (str.Count > 1) Then
  20.  
  21.                 hfPageCount.Value = Convert.ToInt32(str(0)) + 1
  22.                 hflastpagecount.Value = datatable1.Rows.Count Mod _rowCount
  23.             Else
  24.                 hfPageCount.Value = Convert.ToInt32(str(0))
  25.                 hflastpagecount.Value = datatable1.Rows.Count Mod _rowCount
  26.             End If
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.             If (hfCurrentPage.Value = 1) Then
  34.                 hfStartIndex.Value = 0
  35.                 If (hfPageCount.Value = hfCurrentPage.Value) Then
  36.                     hfEndIndex.Value = hflastpagecount.Value - 1
  37.                     btnNext.Enabled = False
  38.                     btnPrevious.Enabled = False
  39.                 Else
  40.                     hfEndIndex.Value = _rowCount - 1
  41.                     btnNext.Enabled = True
  42.                     btnPrevious.Enabled = False
  43.                 End If
  44.  
  45.             Else
  46.                 If (Convert.ToInt32(hfPageCount.Value) > Convert.ToInt32(hfCurrentPage.Value)) Then
  47.                     hfStartIndex.Value = (hfCurrentPage.Value - 1) * _rowCount
  48.                     hfEndIndex.Value = hfStartIndex.Value + _rowCount - 1
  49.                     btnNext.Enabled = True
  50.                     btnPrevious.Enabled = True
  51.                 ElseIf (Convert.ToInt32(hfPageCount.Value) = Convert.ToInt32(hfCurrentPage.Value)) Then
  52.                     hfStartIndex.Value = (hfCurrentPage.Value - 1) * _rowCount
  53.                     If (Convert.ToInt32(hflastpagecount.Value) = 0) Then
  54.                         hfEndIndex.Value = Convert.ToInt32(hfStartIndex.Value) + _rowCount - 1
  55.                     Else
  56.                         hfEndIndex.Value = Convert.ToInt32(hfStartIndex.Value) + Convert.ToInt32(hflastpagecount.Value - 1)
  57.                     End If
  58.  
  59.                     btnNext.Enabled = False
  60.                     btnPrevious.Enabled = True
  61.                 End If
  62.             End If
  63.  
  64.  
  65.  
  66.  
  67.  
  68.             Dim i As Integer
  69.             Dim inhouse As Decimal = 0
  70.             Dim payouts As Decimal = 0
  71.             Dim expenses As Decimal = 0
  72.             Dim net As Decimal = 0
  73.  
  74.  
  75.  
  76.  
  77.             For i = Convert.ToInt32(hfStartIndex.Value) To Convert.ToInt32(hfEndIndex.Value) 'datatable1.Rows.Count - 1
  78.                 dt.Rows.Add(New String() {datatable1.Rows(i)("ID").ToString(), datatable1.Rows(i)("dayy").ToString(), datatable1.Rows(i)("datee").ToString(), datatable1.Rows(i)("Client").ToString(), datatable1.Rows(i)("fromto").ToString(), datatable1.Rows(i)("collect").ToString(), datatable1.Rows(i)("via").ToString(), datatable1.Rows(i)("gross").ToString(), datatable1.Rows(i)("inhouse").ToString(), datatable1.Rows(i)("payouts").ToString(), datatable1.Rows(i)("expenses").ToString(), datatable1.Rows(i)("Net").ToString(), datatable1.Rows(i)("reconciliated").ToString(), datatable1.Rows(i)("farm").ToString()})
  79.  
  80.                 SubTotal = SubTotal + (Convert.ToDecimal(datatable1.Rows(i)("gross").ToString)) 'gross
  81.                 inhouse = inhouse + (Convert.ToDecimal(datatable1.Rows(i)("inhouse").ToString))
  82.                 payouts = payouts + (Convert.ToDecimal(datatable1.Rows(i)("payouts").ToString))
  83.                 expenses = expenses + (Convert.ToDecimal(datatable1.Rows(i)("expenses").ToString))
  84.                 net = net + (Convert.ToDecimal(datatable1.Rows(i)("net").ToString))
  85.  
  86.             Next
  87.  
  88.             If (btnType = "next") Then
  89.                 hfTotalGross.Value = Convert.ToDecimal(hfTotalGross.Value) + Convert.ToDecimal(SubTotal)
  90.  
  91.                 hfTotalInhouse.Value = Convert.ToDecimal(hfTotalInhouse.Value) + Convert.ToDecimal(inhouse)
  92.                 hfTotalPayouts.Value = Convert.ToDecimal(hfTotalPayouts.Value) + Convert.ToDecimal(payouts)
  93.  
  94.                 hfTotalexpense.Value = Convert.ToDecimal(hfTotalexpense.Value) + Convert.ToDecimal(expenses)
  95.                 hfTotalNet.Value = Convert.ToDecimal(hfTotalNet.Value) + Convert.ToDecimal(net)
  96.             ElseIf (btnType = "pre") Then
  97.  
  98.  
  99.  
  100.                 hfTotalGross.Value = Convert.ToDecimal(hfTotalGross.Value) - Convert.ToDecimal(hfSubGross.Value)
  101.  
  102.                 hfTotalInhouse.Value = Convert.ToDecimal(hfTotalInhouse.Value) - Convert.ToDecimal(hfSubInhouse.Value)
  103.                 hfTotalPayouts.Value = Convert.ToDecimal(hfTotalPayouts.Value) - Convert.ToDecimal(hfSubPayouts.Value)
  104.  
  105.                 hfTotalexpense.Value = Convert.ToDecimal(hfTotalexpense.Value) - Convert.ToDecimal(hfSubexpense.Value)
  106.                 hfTotalNet.Value = Convert.ToDecimal(hfTotalNet.Value) - Convert.ToDecimal(hfSubNet.Value)
  107.             Else
  108.                 hfTotalGross.Value = Convert.ToDecimal(SubTotal)
  109.                 hfTotalInhouse.Value = inhouse
  110.                 hfTotalPayouts.Value = payouts
  111.  
  112.                 hfTotalexpense.Value = expenses
  113.                 hfTotalNet.Value = net
  114.                 btnPrevious.Enabled = False
  115.             End If
  116.             'hfSubVia.Value = via
  117.             hfSubGross.Value = Convert.ToDecimal(SubTotal)
  118.             hfSubInhouse.Value = inhouse
  119.             hfSubPayouts.Value = payouts
  120.             hfSubexpense.Value = expenses
  121.             hfSubNet.Value = net
  122.  
  123.             dt.Rows.Add(New String() {"", "", "", "", "", "Sub Total", "", Convert.ToString(hfSubGross.Value), Convert.ToString(inhouse), Convert.ToString(payouts), Convert.ToString(expenses), Convert.ToString(net), "", ""})
  124.             dt.Rows.Add(New String() {"", "", "", "", "", "Total", "", Convert.ToString(hfTotalGross.Value), Convert.ToString(hfTotalInhouse.Value), Convert.ToString(hfTotalPayouts.Value), Convert.ToString(hfTotalexpense.Value), Convert.ToString(hfTotalNet.Value)})
  125.             ' GridView1.AutoGenerateEditButton = True
  126.             GridView1.DataSource = dt
  127.             GridView1.DataBind()
  128.         Else
  129.             lblmsg.Text = "no result found"
  130.             btnNext.Enabled = False
  131.             btnPrevious.Enabled = False
  132.             btnPrint.Enabled = False
  133.         End If
  134.  
  135.     End Sub
  136.     Public Function GetCustDT() As DataTable
  137.         Dim dt As New DataTable
  138.         dt.Columns.Add("Id", GetType(String))
  139.         dt.Columns.Add("Day", GetType(String))
  140.         dt.Columns.Add("Date", GetType(String))
  141.         dt.Columns.Add("Client", GetType(String))
  142.         dt.Columns.Add("From-To", GetType(String))
  143.         dt.Columns.Add("Collect", GetType(String))
  144.         dt.Columns.Add("Via", GetType(String))
  145.         dt.Columns.Add("Gross", GetType(String))
  146.         dt.Columns.Add("In-House", GetType(String))
  147.         dt.Columns.Add("Payouts", GetType(String))
  148.         dt.Columns.Add("Expenses", GetType(String))
  149.         dt.Columns.Add("Net", GetType(String))
  150.         dt.Columns.Add("Status", GetType(String))
  151.         dt.Columns.Add("Farm", GetType(String))
  152.         Return dt
  153.     End Function
  154.  
  155.     Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  156.         hfCurrentPage.Value = hfCurrentPage.Value - 1
  157.         btnType = "pre"
  158.         setQueryValue()
  159.         getSearchResult(txtDate, txtclient, txtfarm, txtcollect, txtvia, txtgross, txtgross2, txtNet, txtNet2, txtexpenses, txtexpenses2, txtDay, txtdate1, txtdate2)
  160.  
  161.     End Sub
  162.  
  163.     Protected Sub btnnext_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  164.         hfCurrentPage.Value = hfCurrentPage.Value + 1
  165.         btnType = "next"
  166.         setQueryValue()
  167.         getSearchResult(txtDate, txtclient, txtfarm, txtcollect, txtvia, txtgross, txtgross2, txtNet, txtNet2, txtexpenses, txtexpenses2, txtDay, txtdate1, txtdate2)
  168.  
  169.     End Sub
  170.  
  171.  
  172.    
  173.  
  174.     Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
  175.         '  Dim GridView1 As GridView
  176.  
  177.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
  178.         GridView1.EditIndex = e.NewEditIndex
  179.      
  180.         BindData()
  181.     End Sub
  182.  
  183.     Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
  184.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
  185.  
  186.         GridView1.PageIndex = e.NewPageIndex
  187.         'Bind data to the GridView control.
  188.           BindData()
  189.  
  190.     End Sub
  191.     Private Sub BindData()
  192.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
  193.  
  194.         GridView1.DataSource = Session("trackmain")
  195.         GridView1.DataBind()
  196.     End Sub
  197.  
  198.     Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs)
  199.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
  200.  
  201.         GridView1.EditIndex = -1
  202.  
  203.     End Sub
  204.  
  205.     Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
  206.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
  207.  
  208.         Dim dt = CType(Session("trackmain"), DataTable)
  209.  
  210.         'Update the values.
  211.         Dim row = GridView1.Rows(e.RowIndex)
  212.         dt.Rows(row.DataItemIndex)("Id") = (CType((row.Cells(0).Controls(0)), TextBox)).Text
  213.        
  214.  
  215.         'Reset the edit index.
  216.         GridView1.EditIndex = -1
  217.  
  218.  
  219.     End Sub
  220. End Class