This is a migrated thread and some comments may be shown as answers.

[Solved] Get count of radgrid rows in NeeddataSource

2 Answers 915 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 22 Mar 2013, 05:44 PM
I am trying to get the count of the number of rows in the radgrid as part of the needDataSource event.  I needs to change a tab header that sits at top of page based on the number of rows it pulls, tried multiple things but nothing works.  below always returns 0

Protected Sub myRadGridList_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles myRadGridList.NeedDataSource
       Dim Count As Integer = 0
       Dim sqlwhere As String = ""
       GetSrpId()
 
       sql = "Select strssn, strFullname, strRank, strPMOS, Convert(varchar(10), strdob, 111) strDob from MnNgPersonnel.dbo.tblMNNatPersonnel Where strRECPREC = '99999999' and strRECSTAT <> 'M' AND " _
           & "(strUIC = '" & HFID.Value & "' or strAttchUIC = '" & HFID.Value & "') and (strSSN Not IN (Select strssn from tblUnitSRPPersonnelHist where intSRpId = " & HFRID.Value & "  and dtExpire > " _
           & "GETDATE() and bitActive = 1) OR strSSN Not IN (Select strssn from tblUnitSRPPersonnelHist where intSRpId = " & HFAID.Value & " and dtExpire > GETDATE() and bitActive = 1)) " & sqlwhere & ""
 
       myRadGridList.DataSource = getData(sql)
 
       Count = myRadGridList.MasterTableView.Items.Count
 
       tbAnnual.HeaderText = "Annual Reviews (" & Count & ")"
 
       pnlGrid.Visible = True
   End Sub

2 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 22 Mar 2013, 07:58 PM
what sort of object is GetrData?  if it is a dataset, then the number of rows is.... dataset.Tables(*).Rows.Count

the reason the grid itself does not give you the number of rows is because it's too early - it only happens in the ItemDataBound event that you have access to that information (right, Princy? Shinu?)
0
Accepted
Shinu
Top achievements
Rank 2
answered on 25 Mar 2013, 04:36 AM
Hi,

Try the following code.
VB:
Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
    Dim count As Integer = RadGrid1.MasterTableView.Items.Count
End Sub

Thanks,
Shinu.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or