This is a migrated thread and some comments may be shown as answers.

[Solved] Numeric Column Filter Error

3 Answers 208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 29 Jul 2009, 10:47 AM
Hi there,

I have a GridTemplateColumn which is databound to a database table containing items of type float.  The grid works fine in adding, editing, deleting, etc.  The column works as expected when I try to filter on numeric characters (EqualTo, LessThan, etc).  However, if the user attempts to filter on non-numeric characters (eg, SomeText, @£$%, etc), an error is raised.  I either need to stop the user from entering any non-numeric data into the filter textbox or to display some sort of error message when the filter data is invalid.  Any ideas on how to achieve this?

Cheers,

Martin

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 29 Jul 2009, 01:58 PM
Hello Martin,

You can use RadNumericTextBox in FilterTemplate to achieve your goal. The grid default filtering will do the same if the column data type is numeric:

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/filtering/defaultcs.aspx

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Martin
Top achievements
Rank 1
answered on 29 Jul 2009, 03:23 PM
Hi Vlad,

Thanks for your quick response.

I tried adding the RadNumericTextBox in FilterTemplate and it NEARLY works.  As requested, it stops the user from entering any non-numeric data into the textbox, but the Filter Icon has disappeared so I am unable to filter on the column.  Here is my code for the column:

<

 

telerik:GridTemplateColumn

 

 

DataField="Multiplier"

 

 

GroupByExpression="Multiplier Group By Multiplier asc"

 

 

SortExpression="Multiplier"

 

 

UniqueName="MultiplierColumn"

 

 

HeaderText="<%$ Resources:Sustain, General_FactorMultiplier %>"

 

 

FilterImageToolTip="<%$ Resources:Grid, Filter_FilterImageToolTip %>">

 

 

<headerstyle />

 

 


<
FilterTemplate>

 

 

    <telerik:RadNumericTextBox

 

 

        id="tbNumFactMult"

 

 

        runat="server"

 

 

        Text='<%# Bind("Multiplier") %>'

 

 

        CausesValidation="false">

 

 

    </telerik:RadNumericTextBox>

 

 

</FilterTemplate>

 

 


<
EditItemTemplate>

 

 

<asp:TextBox

 

 

id="tbFactMult"

 

 

runat="server"

 

 

Text='<%# Bind("Multiplier") %>'

 

 

CausesValidation="false">

 

 

</asp:TextBox>

 

 

 

<span style="color: Red">&nbsp;*</span>

 

 

<asp:RequiredFieldValidator

 

 

ID="MultiplierFieldValidator"

 

 

ControlToValidate="tbFactMult"

 

 

ErrorMessage="<%$ Resources:Sustain, ValidationText_MandatoryField %>"

 

 

runat="server"

 

 

Display="Dynamic">

 

 

</asp:RequiredFieldValidator>

 

 

<asp:RangeValidator

 

 

ID="MultiplierFieldRangeValidator"

 

 

ControlToValidate="tbFactMult"

 

 

ErrorMessage = "<%$ Resources:Sustain, CRF_FactorMultiplierInvalid%>"

 

 

MinimumValue=0

 

 

MaximumValue=4294967295

 

 

Type="Double"

 

 

Display="Dynamic"

 

 

runat="server">

 

 

</asp:RangeValidator>

 

 

</EditItemTemplate>

 

 

<ItemTemplate>

 

 

<asp:Label

 

 

id="lblFactMult"

 

 

runat="server"

 

 

Text='<%# Eval("Multiplier") %>'>

 

 

</asp:Label>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 


Any ideas what I'm missing?  Am I correct to have a FilterTemplate and an EditItemTemplate?

Thanks,

Martin
0
Yavor
Telerik team
answered on 03 Aug 2009, 09:06 AM
Hi Martin,

When using a filter template, the grid will replace the default filter controls for this column, with whatever you have placed in the filter template. In this case, this is just a simple numeric textbox. In this case, it is up to you to include all the relevant controls in the filter template - the control(s) which will accept the user input, along with the control(s) which would actually trigger the filter command.
Additional information on the setup and logic is demonstrated in the following example:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx

I hope this helps.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Martin
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or