I have a gridview that contains user info and one of the columns is a date when the user was added to the system.
Is it possible to use the GridView.onRowCreated method to check if the user was added within a given time frame? If the user was added within that timeframe, then the row is added, if not, then that row is not added.
Note that I can't modify the datasource of the gridview, so I need to do this somehow as the gridview is being created.
You can use RowBoundData
and set teh row to hide based on your certain condition
Protected Sub GridView_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Visible = True ' base on some condition
End If
End Sub
Another Method is to filter your Data. pass the filter expression in the below function and it will return you the desired output. You can do this before your binding.
Public NotInheritable Class GetFilteredData
Private Sub New()
End Sub
<System.Runtime.CompilerServices.Extension> _
Public Shared Function FilterDataTable(Dt As DataTable, FilterExpression As String) As DataTable
Using Dv As New DataView(Dt)
Dv.RowFilter = FilterExpression
Return Dv.ToTable()
End Using
End Function
End Class
You can filter out your gridview datasource and bind to gridview depends upon your where condition on date column. this will be easy solution than putting condition on the gridview event.
Cheers!!