Server Error
in
'/'
Application.
FieldEditors collection
is
empty.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace
for
more information about the error and where it originated
in
the code.
Exception Details: System.NullReferenceException: FieldEditors collection
is
empty.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified
using
the exception stack trace below.
Stack Trace:
[NullReferenceException: FieldEditors collection
is
empty.]
Telerik.Web.UI.RadFilterDataFieldEditorCollection.System.Collections.Generic.IList<Telerik.Web.UI.RadFilterDataFieldEditor>.get_Item(Int32 index) +156
Telerik.Web.UI.RadFilter.AddChildExpression(RadFilterGroupExpressionItem groupItem, Boolean isGroup) +118
Telerik.Web.UI.RadFilterCommandEventArgs.ExecuteCommand(Object source) +173
Telerik.Web.UI.RadFilter.OnBubbleEvent(Object source, EventArgs args) +185
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
Telerik.Web.UI.RadFilterExpressionItem.OnBubbleEvent(Object source, EventArgs args) +131
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
I received the above error trying to dynamically create Rad Filters. The error occurs on Postback when selecting to add a new filter expression.
I am using Telerik.Web.UI, Version=2013.1.403.35.
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
string
.IsNullOrEmpty(
this
.FilterType))
throw
new
NullReferenceException(
"FilterType must not be undefined."
);
var instance = Activator.CreateInstance(
"MyDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123456789"
,
"MyDLL.Data.Biz.MetaData."
+
this
.FilterType);
PropertyInfo[] properties = instance.GetType().GetProperties(
BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public);
foreach
(PropertyInfo p
in
properties)
{
RadFilterDataFieldEditor f =
null
;
if
(p.PropertyType ==
typeof
(
int
))
{
f =
new
RadFilterNumericFieldEditor();
}
if
(p.PropertyType ==
typeof
(
bool
))
{
f =
new
RadFilterBooleanFieldEditor();
}
if
(p.PropertyType ==
typeof
(DateTime))
{
f =
new
RadFilterDateFieldEditor();
}
if
(p.PropertyType ==
typeof
(
string
))
{
f =
new
RadFilterTextFieldEditor();
}
if
(f !=
null
)
{
filter.FieldEditors.Add(f);
}
if
(!Page.IsPostBack)
{
if
(p.PropertyType ==
typeof
(
int
))
{
f.DisplayName = p.Name.HumanizeString();
f.DataType =
typeof
(
int
);
f.FieldName = p.Name;
f.ToolTip = p.Name;
}
if
(p.PropertyType ==
typeof
(
bool
))
{
f.DisplayName = p.Name.HumanizeString();
f.DataType =
typeof
(
bool
);
f.FieldName = p.Name;
f.ToolTip = p.Name;
}
if
(p.PropertyType ==
typeof
(DateTime))
{
f.DisplayName = p.Name.HumanizeString();
f.DataType =
typeof
(DateTime);
f.FieldName = p.Name;
f.ToolTip = p.Name;
}
if
(p.PropertyType ==
typeof
(
string
))
{
f.DisplayName = p.Name.HumanizeString();
f.DataType =
typeof
(
string
);
f.FieldName = p.Name;
f.ToolTip = p.Name;
}
}
}
}
Thanks for any insight.