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

[Solved] Only allow numeric characters in filter control on RadGrid column

1 Answer 470 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dylan
Top achievements
Rank 1
Dylan asked on 12 Jul 2013, 08:13 PM
I am using an EntityDataSource with my RadGrid, and I have a HyperLinkColumn of integer values that needs to be filterable. My problem is that whenever a string is passed into the filter control, a SqlEntityException is thrown with the following message:

'filtertext' could not be resolved in the current scope or context. Make sure that all referenced
variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly.
Near simple identifier, line 6, column 228.


So, I need a way to prevent the user from entering a string into the filter control. I was able to use a GridMaskedColumn in some cases, but in this particular case, the data in the column needs to be linked to another page, so I'm forced to use a HyperLinkColumn. Any thoughts?

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Jul 2013, 09:09 AM
Hello,

<script type="text/javascript">
        
           function isNumericKey(e) {
               var charInp = window.event.keyCode;
               if (charInp > 31 && (charInp < 48 || charInp > 57)) {
                   return false;
               }
               return true;
           }
       </script>
<Columns>
               <telerik:GridHyperLinkColumn DataTextField="ID" NavigateUrl="http://www.google.co.in/"
                   UniqueName="mycolumn">
               </telerik:GridHyperLinkColumn>
               
           </Columns>
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridFilteringItem)
       {
           GridFilteringItem item = e.Item as GridFilteringItem;
           TextBox txt = item["mycolumn"].Controls[0] as TextBox;
           txt.Attributes.Add("onkeypress", "return isNumericKey(event);");
       }
   }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Dylan
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or