1,105,633 Community Members

validation of textbox in gridview

Member Avatar
divyasrinivasan
Newbie Poster
21 posts since Dec 2008
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi ...
thanks a lot..i got how to edi,update,n delete..now i want to validate the textbox wen i press update...like i want to ckeck for null vlues entry...only numbers.......i am searching for javascript but no proper result...

any links ..pls post....

Member Avatar
Kusno
Junior Poster
191 posts since Aug 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 17 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi divyasrinivasan,

This is for validating textbox for numeric only :

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="OperationSheetMultipleArticle.aspx.vb" Inherits="OperationSheetMultipleArticle" EnableSessionState="true" %>
<%@ OutputCache Location="Client" duration="5" varybyparam="none" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<script type="text/javascript" language=javascript>
function keyDownNumber()
{ 
    var key;    
    if(navigator.appName == 'Microsoft Internet Explorer')
        key = event.keyCode;
    else
        key = event.which
        
    if ( !(key >= 48 && key <= 57) && key != 8 && key != 46 && key != 36 && key != 37)
    {
        event.returnValue = false;        
    }
}
</script>
<head runat="server">
    <title>Operation Sheet</title> 
</head>
<body leftmargin=5 topmargin=3> 
    <form id="form1" runat="server">
 <asp:GridView ID="GVDetail" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="LightGray"
          BorderColor="White" BorderStyle="Ridge" BorderWidth="1px" CaptionAlign="Top" CellPadding="0" Font-Size="12px" Font-Strikeout="False" Font-Underline="False" Height="1px" HorizontalAlign="Left" Style="left: 4px; top: 127px" UpdateAfterCallBack="True" Width="100%"  EmptyDataText="NO RECORD FOUND" PageSize="12">
                    <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                    <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" Font-Italic="False" Font-Underline="False"
                        ForeColor="#E7E7FF" />
                    <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                    <Columns>
                     <asp:templatefield headertext="Del."  >
                            <itemstyle borderstyle="None" font-size="8pt" width="10px" horizontalalign="Center" />
                            <headerstyle font-bold="False" width="10px" font-size="8pt"/>
                            <itemtemplate>
                                <asp:CheckBox id="ChkDelete" runat="server" width="20px"  ></asp:CheckBox>                                                                   
                            </itemtemplate>
                        </asp:templatefield>                         
                         <asp:templatefield headertext="Article No.">
                            <itemstyle borderstyle="None" font-size="8pt" width="20px" />
                            <headerstyle font-bold="False" width="65px" font-size="8pt"/>
                            <itemtemplate>
                                <asp:TextBox id="TxtArticleNo" readonly=true text='<% # eval("ArticleNo") %>' runat="server" width="65px" borderstyle="None" font-size="8pt" BackColor="LightCyan" autocallback=true></asp:TextBox>                                                                                                              
                        </itemtemplate>
                        </asp:templatefield>                         
                        <asp:templatefield headertext="Amount">
                            <itemstyle borderstyle="None" font-size="8pt" width="20px" />
                            <headerstyle font-bold="False" width="65px" font-size="8pt"/>
                            <itemtemplate>
                                <asp:TextBox id="Amount" text='<% # eval("Amount") %>' runat="server" width="65px" borderstyle="None" font-size="8pt" onkeypress="keyDownNumber()"  BackColor="Beige"></asp:TextBox>                                                                                 
                        </itemtemplate>
                        </asp:templatefield>                                                  
                    </Columns>
                    <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
             <AlternatingRowStyle BackColor="LightGray" />
                </asp:GridView>   
</form>
</body>
</html>

Thanks,

Member Avatar
divyasrinivasan
Newbie Poster
21 posts since Dec 2008
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

can u pls explain wat u hVE DONE..PLA

Member Avatar
NeonBlue007
Newbie Poster
4 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi there... still new so please forgive me if I make a mistake... to add validation to a textbox that is inside a gridview...
1. Convert the field into a text field...
2. then add validation into the <EditItemTemplate></EditItemTemplate> and the <InsertItemTemplate></InsertItemTemplate>

as below... :

<asp:TemplateField HeaderText="Client Number" SortExpression="ClientNumber">
            <EditItemTemplate>
                <asp:TextBox ID="txtClientNumber" runat="server" Text='<%# Bind("ClientNumber") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtClientNumber" runat="server" Text='<%# Bind("ClientNumber") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="val1" runat="server"  ControlToValidate="txtClientNumber" ErrorMessage="Client Number Required" Display="Dynamic"></asp:RequiredFieldValidator>                    
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("ClientNumber") %>'></asp:Label>
            </ItemTemplate>
            <ControlStyle CssClass="editControlTextFields" Width="96%" />
            <HeaderStyle Width="110px" />
        </asp:TemplateField>
Member Avatar
jayanthan.jvp
Newbie Poster
1 post since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

how to check the text boxes while editing is the textbox is null or not

Member Avatar
rohand
Posting Whiz in Training
293 posts since Mar 2010
Reputation Points: 1 [?]
Q&As Helped to Solve: 56 [?]
Skill Endorsements: 1 [?]
 
0
 

you can also use in built validation controls provided by .net framework instead of java script.

Member Avatar
cloudlight
Newbie Poster
2 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

USE thid.id as argument in Validate function.
like I have my javascript function validateData(source) and I called it as follows on update link OnClientClick="return validateData(this.id);"

Member Avatar
cloudlight
Newbie Poster
2 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

HERE IS THE LINK TO DEMO THAT I HAVE CREATED
This is very simple demo.

http://www.aboriginalsystems.com/bharatDemo/GrvCellValAccessDemo.zip

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article