在GridView过滤行 [英] filtering rows in a gridview

查看:95
本文介绍了在GridView过滤行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含用户信息和各列中的一个是日期,当用户加入到该系统一个gridview。

I have a gridview that contains user info and one of the columns is a date when the user was added to the system.

是否有可能使用 GridView.onRowCreated 的方法来检查,如果用户是在给定的时间内加入?如果用户在该时间内加入,则行被添加,如果不是,则没有添加该行

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.

请注意,我不能修改在GridView的数据源,所以我需要做这个莫名其妙地为正在创建GridView的。

Note that I can't modify the datasource of the gridview, so I need to do this somehow as the gridview is being created.

推荐答案

您可以使用 RowBoundData ,并设置格兰排躲基于对您一定条件

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


另一种方法是过滤数据。通过过滤器前pression在下面的函数,它将返回你所需的输出。您可以将绑定之前做到这一点。


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

这篇关于在GridView过滤行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆