[RESOLVED] GridView-required Field and regular expressions validator Issues...

Hi I have a website created in asp.net and have the following fields displayed in the grid view linked through a database.

  • <div> <div>

    First_Name   Last_name  City Username  Password Email Mobile Gender

    please let me how I can put validations when the edit button is clicked and the textboxs popout...

    I have tried a lot of ways like edit template and all but they have not been helpful

    Really need urgent help..If you need I can also post the code I am using..

    Thanking in advance..

    </div> </div>

The code I have written till now goes like this :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridView.aspx.cs" Inherits="GridView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Grid View</title>
    
    
    
    <style type="text/css">
        #form1
        {
            height: 974px;
        }
        .style1
        {
        }
        #hidr
        {
            height: 23px;
            width: 51px;
        }
    </style>
</head>
<body style="text-align: center; background-color: #993366">
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        DataKeyNames="ID" DataSourceID="SqlDataSource1" Height="356px"
        Width="360px" onselectedindexchanged="GridView1_SelectedIndexChanged"
        BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
        CellPadding="3" CellSpacing="2"
        onrowupdated="GridView1_RowUpdated">
        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <Columns>

            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
                        CommandName="Update" Text="Update"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
                        CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                        <%--<asp:TextBox ID="TextBox13" runat="server" ></asp:TextBox>--%>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
                        CommandName="Edit" Text="Edit"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
                        CommandName="Delete" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="First_Name" HeaderText="First_Name"
                SortExpression="First_Name" />
            <asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
                SortExpression="Last_Name" />
            <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
            <asp:BoundField DataField="Username" HeaderText="Username"
                SortExpression="Username" />
            <asp:BoundField DataField="Password" HeaderText="Password"
                SortExpression="Password" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="Mobile" HeaderText="Mobile"
                SortExpression="Mobile" />
            <asp:BoundField DataField="Gender" HeaderText="Gender"
                SortExpression="Gender" />
        </Columns>
        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
        <EmptyDataTemplate>
            &nbsp;
        </EmptyDataTemplate>
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
    </asp:GridView>
    <br />
    <asp:Button ID="Button" runat="server" onclick="Button_Click" Text="Insert" />
        <b>&nbsp;&nbsp;<asp:Button ID="Button1" runat="server"
        onclick="Button1_Click" Text="Go Back" />
    &nbsp;&nbsp; </b><asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        DeleteCommand="DELETE FROM [entered] WHERE [ID] = @ID"
        InsertCommand="INSERT INTO [entered] ([First_Name], [Last_Name], [City], [Username], [Password], [Email], [Mobile], [Gender]) VALUES (@First_Name, @Last_Name, @City, @Username, @Password, @Email, @Mobile, @Gender)"
        SelectCommand="SELECT * FROM [entered]"
        UpdateCommand="UPDATE [entered] SET [First_Name] = @First_Name, [Last_Name] = @Last_Name, [City] = @City, [Username] = @Username, [Password] = @Password, [Email] = @Email, [Mobile] = @Mobile, [Gender] = @Gender WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Decimal" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="First_Name" Type="String" />
            <asp:Parameter Name="Last_Name" Type="String" />
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="Username" Type="String" />
            <asp:Parameter Name="Password" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Mobile" Type="Decimal" />
            <asp:Parameter Name="Gender" Type="String" />
            <asp:Parameter Name="ID" Type="Decimal" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="First_Name" Type="String" />
            <asp:Parameter Name="Last_Name" Type="String" />
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="Username" Type="String" />
            <asp:Parameter Name="Password" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Mobile" Type="Decimal" />
            <asp:Parameter Name="Gender" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    <div id="inputForm" style="height: 543px" visible="true" runat="server">
      <br />
        Fi<b>rst Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox1" runat="server" MaxLength="30"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <br />
        <br />
        </span>
        <asp:Label ID="myLabel2" runat="server" Text="Last Name"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox2" runat="server" MaxLength="20"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
            ControlToValidate="TextBox2" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <br />
        <br />
        </span>
        <asp:Label ID="myLabel8" runat="server" Text="Username"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox6" runat="server" MaxLength="15"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
            ControlToValidate="TextBox6" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <br />
        <br />
        </span>
        <asp:Label ID="myLabel9" runat="server" Text="Password"></asp:Label>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox9" runat="server" MaxLength="15"
            style="margin-top: 8px" TextMode="Password"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
            ControlToValidate="TextBox9" ErrorMessage="Required field">Required field</asp:RequiredFieldValidator>
        <br />
        <br />
        </span>
        <asp:Label ID="myLabel3" runat="server" Text="City"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox3" runat="server" MaxLength="25"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
            ControlToValidate="TextBox3" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </span>
        <asp:Label ID="myLabel4" runat="server" Text="Email address"></asp:Label>
        &nbsp;&nbsp; <span class="style1">
        <asp:TextBox ID="TextBox4" runat="server" MaxLength="25"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
            ControlToValidate="TextBox4" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
        runat="server" ErrorMessage="Invalid Email"
        
        
        
        
            ValidationExpression="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co.in))$"
            ControlToValidate="TextBox4"></asp:RegularExpressionValidator>
        <br />
        <br />
        </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
        <asp:Label ID="myLabel6" runat="server" Text="Mobile No."></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox5" runat="server" MaxLength="10"
            ontextchanged="TextBox5_TextChanged"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
            ControlToValidate="TextBox5" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="Validator1" runat="server"
            ControlToValidate="TextBox5" Text="Please enter only numbers"
            ValidationExpression="[0-9]{6,}"></asp:RegularExpressionValidator>
            
            <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" language="javascript">
        $(document).ready(function(){
    
    //called when key is pressed in textbox
    $("#TextBox5").keypress(function (e)  
    {
      //if the letter is not digit then display error and don't type anything
      if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
      {
        //display error message
        $("#errmsg").html("Digits Only").show().fadeOut("slow");
        alert("Only Nos are allowed");
        return false;
      }    
    });

  });
  </script>  
        <br />
        <br />
        <asp:Label ID="myLabel5" runat="server" style="text-align: left"
            Text="Choose Gender"></asp:Label>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
            Height="63px">
            <asp:ListItem Selected="True">Male</asp:ListItem>
            <asp:ListItem>Female</asp:ListItem>
        </asp:RadioButtonList>
        <br />
        <asp:Literal ID="litmsg" runat="server" Text="" Visible="false" />
        <br />
        <br />
        
        <asp:Button ID="myButton2" runat="server" Height="24px"
            onclick="myButton2_Click" Text="Create" />
        &nbsp;</b><span class="style1"></div>
    </form>
</body>
</html>

thoughts on "[RESOLVED] GridView-required Field and regular expressions validator Issues..."

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>