Hi Viktor,
Okay I tried the sample project, but I had to do the following:
- First convert the code from "C#" to "VB".
- Got rid of anything that's related to SQL Server Express - because I don't have SQL Server Express.
- Created my own static table reflecting the data and records of my initial post.
The conversion went well and I was able to build and execute the project without any errors.
However, I still had the same WEIRD, really WEIRD results. The filter worked for all records EXCEPT for the following entries:
- THIS IS IT MAKE NO MISTAKE WHERE YOU ARE THIS IS I
- TO BE OR NOT TO BE THAT IS THE QUESTION
- WHAT IS HAPPENING?
- JACK AND JILL WENT UP THE HILL TO FETCH A PAIL OF
Finally, I have changed DropDownList and instead used RadComboBox - with the same results! I feel I will become famous for discovering these 4 entries that JUST WON'T WORK.
Can you please implement the AllowCustomText() feature of the RadComboBox and make the filter work when TextChanged event work or SelectedIndexChanged events are triggered?
Many thanks in advance.
Virgil
Here is the _Default.ASPX:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="_Default.aspx.vb" Inherits="MyStuff.MyRadGrid" %>
<%@ Register Namespace="MyStuff" TagPrefix="custom" %>
<!DOCTYPE html>
<
head
runat
=
"server"
>
<
title
></
title
>
<
style
type
=
"text/css"
>
</
style
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
runat
=
"server"
ID
=
"RadScriptManager1"
>
</
telerik:RadScriptManager
>
<
telerik:RadScriptBlock
runat
=
"server"
ID
=
"RadCodeBlock1"
>
<
script
type
=
"text/javascript"
>
</
script
>
</
telerik:RadScriptBlock
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
PageSize
=
"20"
OnItemCommand
=
"RadGrid1_ItemCommand"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
CommandItemDisplay
=
"Top"
>
<
CommandItemTemplate
>
<
asp:LinkButton
runat
=
"server"
ID
=
"LinkButton1"
Text
=
"Clear Filters"
CommandName
=
"ClearFilters"
/>
</
CommandItemTemplate
>
<
Columns
>
<
telerik:GridBoundColumn
CurrentFilterFunction
=
"Contains"
HeaderText
=
"CLASSIFICATION"
DataField
=
"CLASSIFICATION"
UniqueName
=
"CLASSIFICATION"
/>
<
custom:MyCustomFilteringColumn
HeaderText
=
"CLASS1"
DataField
=
"CLASS1"
UniqueName
=
"CLASS1"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
form
>
</
body
>
</
html
>
Here is the _Default.ASPX.VB:
Imports
System.Collections.Generic
Imports
System.Configuration
Imports
System.Data
Imports
System.Data.OleDb
Imports
System.Data.SqlClient
Imports
System.Globalization
Imports
System.Linq
Imports
System.Threading
Imports
System.Web
Imports
System.Web.UI
Imports
System.Web.UI.WebControls
Imports
Telerik.Web.UI
Namespace
MyStuff
Partial
Public
Class
MyRadGrid
Inherits
System.Web.UI.Page
Private
staticTable
As
DataTable
Protected
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
staticTable = CreateStaticTable()
RadGrid1.DataSource = staticTable
For
Each
column
As
GridBoundColumn
In
RadGrid1.MasterTableView.Columns
If
TypeOf
column
Is
MyStuff.MyCustomFilteringColumn
Then
TryCast(column, MyStuff.MyCustomFilteringColumn).ListDataSource = GetFilterStaticTable(column.DataField)
TryCast(column, MyStuff.MyCustomFilteringColumn).FilterWidth = Unit.Percentage(99)
End
If
Next
End
Sub
Function
CreateStaticTable()
As
DataTable
Dim
table
As
New
DataTable
table.Columns.Add(
"CLASSIFICATION"
,
GetType
(
String
))
table.Columns.Add(
"CLASS1"
,
GetType
(
String
))
table.Rows.Add(
"111111 2222222222 33333333333 444444444444 555555"
,
"111111 2222222222 33333333333 444444444444 555555"
)
table.Rows.Add(
"AAAAAA BBBBB CCCCCCCCC"
,
"AAAAAA BBBBB CCCCCCCCC"
)
table.Rows.Add(
"HELLO PLANET NIBIRU"
,
"HELLO PLANET NIBIRU"
)
table.Rows.Add(
"HUMPTY DUMPTY SAT ON THE WALL HUMPTY DUMPTY HAD A"
,
"HUMPTY DUMPTY SAT ON THE WALL HUMPTY DUMPTY HAD A"
)
table.Rows.Add(
"KUMUSTA ANDROMEDA ?"
,
"KUMUSTA ANDROMEDA ?"
)
table.Rows.Add(
"THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG NEAR"
,
"THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG NEAR"
)
table.Rows.Add(
"__THIS IS IT MAKE NO MISTAKE WHERE YOU ARE THIS IS I"
,
"THIS IS IT MAKE NO MISTAKE WHERE YOU ARE THIS IS I"
)
table.Rows.Add(
"__TO BE OR NOT TO BE THAT IS THE QUESTION"
,
"TO BE OR NOT TO BE THAT IS THE QUESTION"
)
table.Rows.Add(
"__WHAT IS HAPPENING?"
,
"WHAT IS HAPPENING?"
)
table.Rows.Add(
"WHAT THE FREAK?"
,
"WHAT THE FREAK?"
)
table.Rows.Add(
"XXXXXXXXXXX YYYYYYYYYYYY ZZZZZZZZZZZZ"
,
"XXXXXXXXXXX YYYYYYYYYYYY ZZZZZZZZZZZZ"
)
table.Rows.Add(
"YYYYYYYYYYYY ZZZZZZZZZZZZ XXXXXXXXXXXX"
,
"YYYYYYYYYYYY ZZZZZZZZZZZZ XXXXXXXXXXXX"
)
table.Rows.Add(
"ZZZZZZZZZZ XXXXXXXXX YYYYYYYYY"
,
"ZZZZZZZZZZ XXXXXXXXX YYYYYYYYY"
)
table.Rows.Add(
"__JACK AND JILL WENT UP THE HILL TO FETCH A PAIL OF"
,
"JACK AND JILL WENT UP THE HILL TO FETCH A PAIL OF"
)
table.Rows.Add(
"HUMPTY DUMPTY SAT ON A WALL. HUMPTY DUMPTY HAD A"
,
"HUMPTY DUMPTY SAT ON A WALL. HUMPTY DUMPTY HAD A"
)
Return
table
End
Function
Private
Function
GetFilterStaticTable(Field
As
String
)
As
DataTable
Dim
dtDistinct
As
DataTable =
New
DataTable
dtDistinct = staticTable.DefaultView.ToTable(
True
, Field)
Return
dtDistinct
End
Function
Protected
Sub
RadGrid1_ItemCommand(source
As
Object
, e
As
GridCommandEventArgs)
If
e.CommandName =
"ClearFilters"
Then
For
Each
column
As
GridColumn
In
RadGrid1.MasterTableView.Columns
column.CurrentFilterFunction = GridKnownFunction.NoFilter
column.CurrentFilterValue = [
String
].Empty
Next
RadGrid1.MasterTableView.FilterExpression = [
String
].Empty
RadGrid1.MasterTableView.Rebind()
End
If
End
Sub
End
Class
End
Namespace
Here is the MyCustomFilteringColumn.VB :
Imports
System.Collections.Generic
Imports
System.Linq
Imports
System.Web
Imports
System.Web.UI
Imports
System.Web.UI.WebControls
Imports
Telerik.Web.UI
Namespace
MyStuff
Public
Class
MyCustomFilteringColumn :
Inherits
GridBoundColumn
Private
m_listDataSource
As
Object
=
Nothing
Private
_filterWidth
As
Unit =
Nothing
'RadGrid calls this method when it initializes the controls inside the filtering item cells
Public
Property
FilterWidth
As
Unit
Get
Return
_filterWidth
End
Get
Set
(
ByVal
value
As
Unit)
_filterWidth = value
End
Set
End
Property
Protected
Overrides
Sub
SetupFilterControls(cell
As
TableCell)
MyBase
.SetupFilterControls(cell)
cell.Controls.RemoveAt(0)
Dim
list
As
New
RadComboBox()
list.ID =
"list"
+
Me
.DataField
list.AutoPostBack =
True
AddHandler
list.SelectedIndexChanged,
AddressOf
list_SelectedIndexChanged
cell.Controls.AddAt(0, list)
cell.Controls.RemoveAt(1)
list.DataTextField =
Me
.DataField
list.DataValueField =
Me
.DataField
list.DataSource =
Me
.ListDataSource
list.Width = _filterWidth
End
Sub
Private
Sub
list_SelectedIndexChanged(sender
As
Object
, e
As
EventArgs)
Dim
filterItem
As
GridFilteringItem = TryCast(TryCast(sender, RadComboBox).NamingContainer, GridFilteringItem)
If
Me
.DataType = System.Type.[
GetType
](
"System.Int32"
)
OrElse
Me
.DataType = System.Type.[
GetType
](
"System.Int16"
)
OrElse
Me
.DataType = System.Type.[
GetType
](
"System.Int64"
)
Then
filterItem.FireCommandEvent(
"Filter"
,
New
Pair(
"EqualTo"
,
Me
.UniqueName))
Else
' treat everything else like a string
filterItem.FireCommandEvent(
"Filter"
,
New
Pair(
"Contains"
,
Me
.UniqueName))
End
If
End
Sub
Public
Property
ListDataSource()
As
Object
Get
Return
Me
.m_listDataSource
End
Get
Set
m_listDataSource = value
End
Set
End
Property
'RadGrid calls this method when the value should be set to the filtering input control(s)
Protected
Overrides
Sub
SetCurrentFilterValueToControl(cell
As
TableCell)
MyBase
.SetCurrentFilterValueToControl(cell)
Dim
list
As
RadComboBox =
DirectCast
(cell.Controls(0), RadComboBox)
If
Me
.CurrentFilterValue <>
String
.Empty
Then
list.SelectedValue =
Me
.CurrentFilterValue
End
If
End
Sub
'RadGrid calls this method to extract the filtering value from the filtering input control(s)
Protected
Overrides
Function
GetCurrentFilterValueFromControl(cell
As
TableCell)
As
String
Dim
list
As
RadComboBox =
DirectCast
(cell.Controls(0), RadComboBox)
Return
list.SelectedValue
End
Function
Protected
Overrides
Function
GetFilterDataField()
As
String
Return
Me
.DataField
End
Function
End
Class
End
Namespace
Here is the web.config:
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!--
For more information on how to configure your ASP.NET application, please visit
-->
<
configuration
>
<
appSettings
>
<
add
key
=
"webpages:Enabled"
value
=
"true"
/>
</
appSettings
>
<
connectionStrings
>
</
connectionStrings
>
<!--
The following attributes can be set on the <
httpRuntime
> tag.
<
system.Web
>
<
httpRuntime
targetFramework
=
"4.5"
/>
</
system.Web
>
-->
<
system.web
>
<
customErrors
mode
=
"Off"
/>
<
compilation
debug
=
"true"
targetFramework
=
"4.5"
>
<
assemblies
>
</
assemblies
>
</
compilation
>
<
httpRuntime
maxRequestLength
=
"2097151"
requestValidationMode
=
"2.0"
/>
<
pages
validateRequest
=
"false"
controlRenderingCompatibilityVersion
=
"4.0"
>
<
controls
>
<
add
tagPrefix
=
"telerik"
assembly
=
"Telerik.Web.UI"
namespace
=
"Telerik.Web.UI"
/>
</
controls
>
</
pages
>
<
httpHandlers
>
<
add
path
=
"Telerik.Web.UI.WebResource.axd"
type
=
"Telerik.Web.UI.WebResource"
verb
=
"*"
validate
=
"false"
/>
</
httpHandlers
>
</
system.web
>
<
system.webServer
>
<
validation
validateIntegratedModeConfiguration
=
"false"
/>
<
handlers
>
<
add
name
=
"Telerik_Web_UI_WebResource_axd"
verb
=
"*"
preCondition
=
"integratedMode"
path
=
"Telerik.Web.UI.WebResource.axd"
type
=
"Telerik.Web.UI.WebResource"
/>
</
handlers
>
</
system.webServer
>
</
configuration
>