|
Imports System |
Imports System.Data |
Imports System.Configuration |
Imports System.Collections |
Imports System.Web |
Imports System.Web.Security |
Imports System.Web.UI |
Imports System.Web.UI.WebControls |
Imports System.Web.UI.WebControls.WebParts |
Imports System.Web.UI.HtmlControls |
Imports Telerik.Web.UI |
|
Public Partial Class FilterOneButton |
Inherits System.Web.UI.Page |
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) |
AddHandler RadGrid1.ItemCommand, AddressOf RadGrid1_ItemCommand |
AddHandler RadGrid1.ItemCreated, AddressOf RadGrid1_ItemCreated |
AddHandler RadGrid1.PreRender, AddressOf RadGrid1_PreRender |
End Sub |
|
Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) |
If RadGrid1.AllowFilteringByColumn Then |
Dim item As GridHeaderItem = TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.Header)(0), GridHeaderItem) |
(TryCast(item("CommandColumn").FindControl("ToggleFilterButton"), ImageButton)).ImageUrl = "~/moveup.gif" |
(TryCast(item("CommandColumn").FindControl("FilterButton"), ImageButton)).Visible = True |
Else |
Dim item As GridHeaderItem = TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.Header)(0), GridHeaderItem) |
(TryCast(item("CommandColumn").FindControl("ToggleFilterButton"), ImageButton)).ImageUrl = "~/movedown.gif" |
(TryCast(item("CommandColumn").FindControl("FilterButton"), ImageButton)).Visible = False |
End If |
End Sub |
|
Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) |
If e.CommandName = "ToggleFilter" Then |
RadGrid1.AllowFilteringByColumn = Not RadGrid1.AllowFilteringByColumn |
RadGrid1.Rebind() |
End If |
|
If e.CommandName = "FilterAll" Then |
Dim item As GridFilteringItem = TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem) |
Dim employeeId As String = (TryCast(item("EmployeeID").Controls(0), TextBox)).Text |
Dim name As String = (TryCast(item("LastName").Controls(0), TextBox)).Text |
Dim title As String = (TryCast(item("Title").Controls(0), TextBox)).Text |
Dim picker As RadDatePicker = (TryCast(item("HireDate").Controls(0), RadDatePicker)) |
Dim hireDate As String = IIf(picker.SelectedDate <> Nothing,picker.SelectedDate.Value.ToShortDateString(),"") |
Dim city As String = (TryCast(item("City").Controls(0), TextBox)).Text |
Dim expression As String = "" |
|
If employeeId <> "" Then |
expression += "([EmployeeID] = " + employeeId + ")" |
End If |
If name <> "" Then |
If expression <> "" Then |
expression += " AND " |
End If |
expression += "([LastName] LIKE '%" + name + "%')" |
End If |
If title <> "" Then |
If expression <> "" Then |
expression += " AND " |
End If |
expression += "([Title] LIKE '%" + title + "%')" |
End If |
If hireDate <> "" Then |
If expression <> "" Then |
expression += " AND " |
End If |
expression += "([HireDate] = '" + hireDate + "')" |
End If |
If city <> "" Then |
If expression <> "" Then |
expression += " AND " |
End If |
expression += "([City] LIKE '%" + city + "%')" |
End If |
|
RadGrid1.MasterTableView.FilterExpression = expression |
RadGrid1.Rebind() |
End If |
End Sub |
|
Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) |
If TypeOf e.Item Is GridFilteringItem Then |
Dim item As GridFilteringItem = TryCast(e.Item, GridFilteringItem) |
item("EmployeeID").Controls(1).Visible = False |
item("LastName").Controls(1).Visible = False |
item("Title").Controls(1).Visible = False |
item("HireDate").Controls(2).Visible = False |
item("City").Controls(1).Visible = False |
End If |
End Sub |
End Class |