TelerikDeveloper.com

TelerikDeveloper.com

sgray128 11/8/2013 2:03:21 PM

ASP-NET - Grid Filtering

This article shows how to filter ASP.NET grids                       


In the header, add AllowFilteringByColumns, add the GroupSettings node so the filtering will not be case sensitive. Add AutoPostPackOnFilter for each column

 

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"  AllowFilteringByColumn="true"
    CssClass="grid" PageSize="50" AllowPaging="true"
    Width="100%" ShowFooter="false" CellSpacing="0" CellPadding="0" GridLines="None">
    <GroupingSettings CaseSensitive="false" />
    <MasterTableView DataKeyNames="custnmbr" ShowGroupFooter="false">
        <Columns>
            <telerik:GridButtonColumn ButtonType="LinkButton" Text="select" ItemStyle-Width="80px" ></telerik:GridButtonColumn>
            <telerik:GridBoundColumn DataField="custnmbr" HeaderText="Customer Number" ItemStyle-Width="80px" AutoPostBackOnFilter="true" ReadOnly="True"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="custname" HeaderText="Customer Name" AutoPostBackOnFilter="true" ReadOnly="True"></telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

 This code will provide an 'empty message'

If TypeOf e.Item Is GridFilteringItem Then
    Dim filter As GridFilteringItem = DirectCast(e.Item, GridFilteringItem)
    For Each col As GridColumn In RadGrid1.MasterTableView.RenderColumns
 
        If col.OrderIndex > 1 AndAlso col.ColumnType = "GridBoundColumn" Then
            Dim txtbx As TextBox = TryCast(filter(col.UniqueName).Controls(0), TextBox)
            If txtbx.Text = "" Then
                txtbx.Text = "Filter text"
            End If
        End If
    Next
End If