Click here to Skip to main content
14,928,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

Try This......

Add columns in Grid control then in Column Properties -Group Format- Format Type select Numeric...
   
v2
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[^]
   
Hi,

You can use AJAX FilterTextBoxExtender to filter the characters entered in the textbox.

Here is the sample code for you

XML
<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 :)

Regards,
Manoj
   
May be u can user a REgularexpressionvalidator..


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

<asp:templatefield headertext="OnlyNumbers">
<itemtemplate>

<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"/>





   

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900