Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
Hi every one I am faceing problem with gridview editing value-
 
Que:- How to restrict gridview column to accept only numbers at client side
Suppose there is two columns in gridview and i want that first column should take
alphabets and second should take numbers only...
 
I have tried onKeyPress event in asp page but not works...
 
waiting for your suggestion.
thanks in advance.
Posted 9-May-13 2:41am
TrushnaK11.2K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try This......
 
Add columns in Grid control then in Column Properties -Group Format- Format Type select Numeric...
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use templated field with masked edit for a textbox in grid view, follow this link , to know use of maskedit ajax toolkit
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
You can use AJAX FilterTextBoxExtender to filter the characters entered in the textbox.
 
Here is the sample code for you
 
<asp:ScriptManager ID="SM1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:TextBox ID="txtNumeric" runat="server"></asp:TextBox>
                <ajax:FilteredTextBoxExtender ID="FTBE_txtNumeric" runat="server" FilterType="Numbers" TargetControlID="txtNumeric"></ajax:FilteredTextBoxExtender>
                <br />
                <asp:TextBox ID="txtAlphabet" runat="server"></asp:TextBox>
                <ajax:FilteredTextBoxExtender ID="FTBE_txtAlphabet" runat="server" FilterType="UppercaseLetters,LowercaseLetters" TargetControlID="txtAlphabet"></ajax:FilteredTextBoxExtender>
            </ContentTemplate>
        </asp:UpdatePanel>
 
You can follow the below link for more queries
 
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/FilteredTextBox/FilteredTextBox.aspx[^]
 
Happy coding Smile | :)
 
Regards,
Manoj
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

May be u can user a REgularexpressionvalidator..
 

<asp:gridview id="mygrd" runat="server" visible="true" xmlns:asp="#unknown">


<asp:boundfield headertext="Alphabets">

<asp:templatefield headertext="OnlyNumbers">


<asp:textbox id="txtBox1" runat="server">
<asp:regularexpressionvalidator id="RegularExpressionValidator1">
ControlToValidate="txtBox1"
ValidationExpression="\d+"
Display="Static"
EnableClientScript="true"
ErrorMessage="Please enter numbers only"
runat="server"/>
 



 

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 9 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100