MANU BAR

banner image
banner image

Validation with Registrationform

 Validation with Registrationform





<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="StoreProcedured.Registration" UnobtrusiveValidationMode="None"%>

 

<form id="form1" runat="server">

    <div>

            <table class="auto-style1">

            <tr>

                <td class="auto-style2">Name</td>

                <td>

<asp:TextBox ID="TextBox1" runat="server" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style5">

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Name is Required." ForeColor="#FF3300"></asp:RequiredFieldValidator>

                </td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">Address</td>

                <td>

<asp:TextBox ID="TextBox2" runat="server" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style5">

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" Display="Dynamic" ErrorMessage="Please Enter Address" ForeColor="Red" ViewStateMode="Enabled">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style3">Contact No.</td>

                <td class="auto-style4">

                    <asp:TextBox ID="TextBox3" runat="server" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style6">

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3" Display="Dynamic" ErrorMessage="Contact no is required." ForeColor="Red">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style6">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">Email</td>

                <td>

<asp:TextBox ID="TextBox4" runat="server" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style5">

<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox4" Display="Dynamic" ErrorMessage="Email is required." ForeColor="Red">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style5">

                    &nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">City</td>

                <td>

<asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="137px">

                        <asp:ListItem>Vidisha</asp:ListItem>

                        <asp:ListItem>Bhopal</asp:ListItem>

                        <asp:ListItem>Indore</asp:ListItem>

                    </asp:DropDownList>

                </td>

                <td class="auto-style5">

                    &nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style7">Password</td>

                <td class="auto-style8">

<asp:TextBox ID="TextBox5" runat="server" TextMode="Password" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style9">

<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TextBox5" Display="Dynamic" ErrorMessage="Password is Requried." ForeColor="Red">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style9"></td>

            </tr>

            <tr>

                <td class="auto-style2">Gender</td>

                <td>

<asp:RadioButton ID="RadioButton1" runat="server"GroupName="G" Text="Male" />

<asp:RadioButtonID="RadioButton2"runat="server"GroupName="G" Text="Female" />

             </td>

                <td class="auto-style5">

<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" ErrorMessage="Please Select Gender." ForeColor="Red" OnServerValidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>

                </td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">Subject</td>

                <td>

<asp:CheckBox ID="CheckBox1" runat="server" Text="Hindi" />

<asp:CheckBox ID="CheckBox2" runat="server" Text="English" />

<asp:CheckBox ID="CheckBox3" runat="server" Text="Math" />

                </td>

                <td class="auto-style5">&nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">Message</td>

                <td>

<asp:TextBox ID="TextBox6" runat="server" Height="87px" TextMode="MultiLine" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style5">

<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="TextBox6" Display="Dynamic" ErrorMessage="Message is required." ForeColor="Red">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">&nbsp;</td>

                <td>&nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

          

            <tr>

                <td class="auto-style2">&nbsp;</td>

                <td style="text-align: center">

                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />

                </td>

                <td class="auto-style5">&nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

        </table>   </div>     </form>


CREATE TABLE [dbo].[Registration_Table] (

    [Id]       INT             IDENTITY (1, 1) NOT NULL,

    [Name]     NVARCHAR (50)   NULL,

    [Address]  NVARCHAR (50)   NULL,

    [Contact]  NVARCHAR (50)   NULL,

    [Email]    NVARCHAR (50)   NULL,

    [City]     NVARCHAR (50)   NULL,

    [Password] NVARCHAR (50)   NULL,

    [Gender]   NVARCHAR (50)   NULL,

    [Hindi]    NVARCHAR (50)   NULL,

    [English]  NVARCHAR (50)   NULL,

    [Math]     NVARCHAR (50)   NULL,

    [Message]  NVARCHAR (1000) NULL,

    CONSTRAINT [PK_Registration_Table] PRIMARY KEY CLUSTERED ([Id] ASC)

);

 

 

----------------------------------------------------------------

GridView

--------------------------------------------------------------------------

STORED PROCEDURE EXAMPLE

CREATE PROCEDURE [dbo].[SelectData]

AS

     SELECT *from Registration_Table

RETURN 0

exec [SelectData]

---------------------------------------------

Code:-

void show()

        {

            string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

            SqlConnection con = new SqlConnection(conn_str);

            SqlDataAdapter da = new SqlDataAdapter("SelectData", con);

            try

            {

                con.Open();

                DataSet ds = new DataSet();

                da.Fill(ds);

                GridView1.DataSource = ds.Tables[0];

                GridView1.DataBind();

                con.Close();

            }

            catch (Exception ex)

            {

                Response.Write(ex.Message);

            }

        }

SecondWay:

string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

            SqlConnection con = new SqlConnection(conn_str);

            SqlCommand cmd = new SqlCommand();

            cmd.Connection = con;

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.CommandText = "SelectData";

            con.Open();

           // cmd.Parameters.AddWithValue("@id", Convert.ToInt32(TextBox1.Text));

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();

            da.Fill(dt);

            GridView1.DataSource = dt;

            GridView1.DataBind();

            con.Close();

--------------------------------------------

STOREED PROCEDURE: Search Data ById:

--------------------------------------------

CREATE PROCEDURE [dbo].[SelectDataById]

     @id int

AS

     SELECT *from Registration_Table where Id=@id

RETURN 0

 

exec SelectDataById 1

 

-----------------------------------------------------------

 

  protected void Button1_Click(object sender, EventArgs e)

        {

string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

 SqlConnection con = new SqlConnection(conn_str);

 SqlCommand cmd = new SqlCommand("SelectDataById", con);

 cmd.CommandType = CommandType.StoredProcedure;

 cmd.Parameters.AddWithValue("@id", Convert.ToInt32(TextBox1.Text));

        try

            {

                con.Open();

                GridView1.DataSource = cmd.ExecuteReader();

                GridView1.DataBind();

                con.Close();

            }

            catch (Exception ex)

            {

                Response.Write(ex.Message);

            }

        }

--------------------------------------------

STOREED PROCEDURE: Search Data ById:

--------------------------------------------

CREATE PROCEDURE [dbo].[SelectDataById]

     @id int

AS

     SELECT *from Registration_Table where Id=@id

RETURN 0

 

exec SelectDataById 1

 

------------------------------------------------------------------

string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

SqlConnection con = new SqlConnection(conn_str);

SqlCommand cmd = new SqlCommand();

cmd.Connection = con;

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "SelectDataById";

con.Open();

cmd.Parameters.AddWithValue("@id", Convert.ToInt32(TextBox1.Text));

SqlDataAdapter da = new SqlDataAdapter(cmd);

          

//DataTable dt = new DataTable();

  DataSet DS = new DataSet();

//da.Fill(dt);

   da.Fill(DS);

// GridView1.DataSource = dt;

    GridView1.DataSource = DS;

GridView1.DataBind();

con.Close();

---------------------------------------------------------

 


 

DELETE PROCEDURE CODE:

CREATE PROCEDURE [dbo].[ProDelete]

     @Id int

    

AS

     delete from Registration_Table where Id=@Id;

RETURN 0

--------------------------------------------------------------------------------------------------------------

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

        {

            string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

            SqlConnection con = new SqlConnection(conn_str);

            SqlCommand cmd = new SqlCommand("ProDelete", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@Id",GridView1.Rows[e.RowIndex].Cells[3].Text);

            try

            {

                con.Open();

                cmd.ExecuteNonQuery();

                con.Close();

                Response.Write("Record Deleted....."+GridView1.Rows[e.RowIndex].Cells[3].Text);

            }

            catch (Exception Ex)

            {

                Response.Write(Ex.Message);

            }

            show();

        }


 

UPDATING USING STORED PROCEDURE

UPDATE STORE PROCEDURE:

CREATE PROCEDURE [dbo].[UdateDataPro]

@Id int,

@Name nvarchar(50),

@Address nvarchar(50),

@Contact nvarchar(50)

AS

Update Registration_Table set Name=@Name, Address=@Address, Contact=@Contact where Id=@Id

RETURN 0

--------------------------------------------------------------------------------------------

1)  Add Grid view

2)  Then Add Template Field Then Change Header Text.

3)  इसके बाद हम <ItemTemplate> Field मैं Label Add कर इसकी Property को Eval(“FieldName”) के साथ Bind करते है।

4)  इसके बाद हम <EditTemplate> Field मैं TextBox Add कर इसकी Property को Eval(“FieldName”) के साथ Bind करते है।

5)   

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" style="text-align: center">

 

<Columns>

<asp:TemplateField HeaderText="Id">

<EditItemTemplate>

<asp:TextBox ID="TextBox2" runat="server" ReadOnly="True" Text='<%# Eval("Id") %>'></asp:TextBox> </EditItemTemplate>

<ItemTemplate>

<asp:Label ID="Label1" runat="server" Text='<%# Eval("Id") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

 

<asp:TemplateField HeaderText="Name">

<EditItemTemplate>

<asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>

</EditItemTemplate>

 

<ItemTemplate>

<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

 

<asp:TemplateField HeaderText="Address">

<EditItemTemplate>

<asp:TextBox ID="TextBox4" runat="server" Text='<%# Eval("Address") %>'></asp:TextBox>

</EditItemTemplate>

 

<ItemTemplate>

<asp:Label ID="Label3" runat="server" Text='<%# Eval("Address") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

 

<asp:TemplateField HeaderText="Contact">

<EditItemTemplate>

<asp:TextBox ID="TextBox5" runat="server" Text='<%# Eval("Contact") %>'></asp:TextBox>

</EditItemTemplate>

 

<ItemTemplate>

<asp:Label ID="Label4" runat="server" Text='<%# Eval("Contact") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:CommandField ShowEditButton="True" />

 

</Columns>

</asp:GridView>

using System;

using System.Collections.Generic;

using System.Data;

using System.Data.SqlClient;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

namespace StoreProcedured

{

public partial class SearchDataStoreProcedure : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

show();

} }

void show() {

string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

SqlConnection con = new SqlConnection(conn_str);

SqlCommand cmd = new SqlCommand();

cmd.Connection = con;

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "Select_Data";

con.Open();

// cmd.Parameters.AddWithValue("@id", Convert.ToInt32(TextBox1.Text));

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataTable dt = new DataTable();

da.Fill(dt);

GridView1.DataSource = dt;

GridView1.DataBind();

con.Close(); }     

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)

        {

            GridView1.EditIndex = e.NewEditIndex;

            show();

        }

 

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

        {

 

TextBox Name = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3");

TextBox Address = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox4");

TextBox Contact = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox5");

TextBox Id = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2");

string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

SqlConnection con = new SqlConnection(conn_str);

SqlCommand cmd = new SqlCommand("UdateDataPro", con);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@Name", Convert.ToString(Name.Text));

cmd.Parameters.AddWithValue("@Address", Convert.ToString(Address.Text));

cmd.Parameters.AddWithValue("@Contact", Convert.ToString(Contact.Text));

cmd.Parameters.AddWithValue("@Id", Convert.ToInt32(Id.Text));

try

{

con.Open();

cmd.ExecuteNonQuery();

con.Close();

Response.Write("Updated......");

}

catch (Exception Ex)

{   Response.Write(Ex.Message); }

 

 GridView1.EditIndex = -1;

 show();

}

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)

{

GridView1.EditIndex = -1;

show();

}

}

}

SEARCH PROCEDURE:

CREATE PROCEDURE [dbo].[SelectDataById]

     @id int

AS

     SELECT *from Registration_Table where Id=@id

RETURN 0

-----------

protected void Button1_Click(object sender, EventArgs e)

        {

          

           string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

            SqlConnection con = new SqlConnection(conn_str);

            SqlCommand cmd = new SqlCommand();

            cmd.Connection = con;

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.CommandText = "SelectDataById";

            con.Open();

 

            cmd.Parameters.AddWithValue("@id", Convert.ToInt32(TextBox1.Text));

            SqlDataAdapter da = new SqlDataAdapter(cmd);

 

            //DataTable dt = new DataTable();

            DataSet DS = new DataSet();

            //da.Fill(dt);

            da.Fill(DS);

            // GridView1.DataSource = dt;

            GridView1.DataSource = DS;

            GridView1.DataBind();

            con.Close();

}

 

DELETE PROCEDURE

 

CREATE PROCEDURE [dbo].[ProDelete]

     @Id int

AS

     delete from Registration_Table where Id=@Id;

RETURN 0

 

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

        {

Label Id = (Label)GridView1.Rows[e.RowIndex].FindControl("Label1");

string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

SqlConnection con = new SqlConnection(conn_str);

SqlCommand cmd = new SqlCommand("ProDelete", con);

cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id",Convert.ToInt32(Id.Text));

            try

            {

                con.Open();

                cmd.ExecuteNonQuery();

                con.Close();

                Response.Write("Deleted......");

            }

            catch (Exception Ex)

            {

                Response.Write(Ex.Message);

            }

 

          //  Response.Write(Id.Text);

 show();  }

 

Registration From with Validation

 

Validation Code:web.config file Code:

<configuration>

<appSettings>

    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

</appSettings>

</configuration>

Page Directive Code:

<%@ Page Language="C#" UnobtrusiveValidationMode="None"%>

 

Stored Procedure:

USE [RegistrationTbl]

GO

/****** Object:  StoredProcedure [dbo].[INSERT_SP]    Script Date: 01/24/2021 07:00:26 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE [dbo].[INSERT_SP]

@Name nvarchar(50),    @Address nvarchar(50),

@Contact nvarchar(50), @Email nvarchar(50),

@City nvarchar(50),    @Password nvarchar(50),

@Gender nvarchar(50),  @Hindi nvarchar(50),

@English nvarchar(50), @Math nvarchar(50),

@Message nvarchar(100)

as

Begin

insert into Registration_Table (Name,Address,Contact,Email,City,Password,Gender,Hindi,English, Math,Message) values(@Name,@Address,@Contact,@Email,@City,@Password,@Gender,@Hindi,@English,@Math,@Message);

end;

 

exec[INSERT_SP] 'ram','vds','7415663588','abc@gmail.com','city', '12','male','Hindi','English','Math','hello'

 

ButtonCode File:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

namespace StoreProcedured

{

    public partial class Registration : System.Web.UI.Page

    {

        public string Gender;

        public string Hindi_Data;

        public string English_Data;

        public string Math_Data;

 

        protected void Page_Load(object sender, EventArgs e)

        {

            RadioButton1.AutoPostBack = true;

            RadioButton2.AutoPostBack = true;

            DropDownList1.AutoPostBack = true;

        }

        String Get_Gender()

        {

            if (RadioButton1.Checked)

            {   Gender = "Male";   }

            if (RadioButton2.Checked)

            {   Gender = "Female";  }

            return Gender;

        }

        String Get_H()

        {

            if (CheckBox1.Checked)

            {   Hindi_Data = "YES"; }

            else

            {   Hindi_Data = "NO"; }

            return Hindi_Data;

        }

        String Get_E()

        {

            if (CheckBox2.Checked)

            {   English_Data = "YES";}

            Else { English_Data = "NO";}

            return English_Data;

        }

        String Get_M()

        {

            if (CheckBox1.Checked)

            {   Math_Data = "YES";}

            else

            { Math_Data = "NO";}

            return Math_Data;

        }

protected void Button1_Click(object sender, EventArgs e)

  {

string conn_str=@"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

            SqlConnection con = new SqlConnection(conn_str);

            SqlCommand cmd = new SqlCommand("INSERT_SP",con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@Name", TextBox1.Text);

            cmd.Parameters.AddWithValue("@Address", TextBox2.Text);

            cmd.Parameters.AddWithValue("@Contact", TextBox3.Text);

            cmd.Parameters.AddWithValue("@Email", TextBox4.Text);

            cmd.Parameters.AddWithValue("@City", DropDownList1.Text);

 

            cmd.Parameters.AddWithValue("@Password", TextBox5.Text);

            cmd.Parameters.AddWithValue("@Gender", Get_Gender());

            cmd.Parameters.AddWithValue("@Hindi", Get_H());

            cmd.Parameters.AddWithValue("@English", Get_E());

            cmd.Parameters.AddWithValue("@Math", Get_M());

            cmd.Parameters.AddWithValue("@Message", TextBox6.Text);

 

            try

            {

                con.Open();

                cmd.ExecuteNonQuery();

                con.Close();

                Response.Write("Registration Successfully..");

 Response.Write("<a href='LoginSystem.aspx'>Click Here to Login</a>");

          }

     catch (Exception Ex)

            {  Response.Write(Ex.Message); }

        }

 

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)// This is an event

        {

            if (RadioButton1.Checked || RadioButton2.Checked)

            {   args.IsValid = true; }

            else

            {   args.IsValid = false;  }

            }

        }

    }

 

 

Stored Procedure:

 

CREATE PROCEDURE [dbo].[LoginUser]

     -- Add the parameters for the stored procedure here

     @Email nvarchar(50),

     @Password nvarchar(50)

AS

BEGIN

     SELECT *From dbo.Registration_Table where Email=@Email and Password=@Password

 

END

 

protected void Button1_Click(object sender, EventArgs e)

        {

            string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

            SqlConnection con = new SqlConnection(conn_str);

            SqlCommand cmd = new SqlCommand("LoginUser", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@Email", TextBox1.Text);

            cmd.Parameters.AddWithValue("@Password", TextBox2.Text);

            con.Open();

            SqlDataReader dr = cmd.ExecuteReader(); // to store row in dr;

            //  Response.Write(dr.HasRows.ToString()); // return true and false

            if (dr.HasRows)

            {

                Session["Email"] = TextBox1.Text;

                Response.Redirect("Dashboard.aspx?Email=" + TextBox1.Text);

            }

            else

            { Response.Write("Email Id and Password is Invalid..."); }

            con.Close();

                      

            //if (dr.Read())

            //{

            //    string Email= dr["Email"].ToString();

            //    string Password =dr["Password"].ToString();

            //    if (TextBox1.Text == Email && TextBox2.Text == Password)

            //    {

            //        Response.Redirect("Dashboard.aspx?Email=" + dr["Email"]);

            //    }

            //    else

            //     {

            //      Response.Write("Email Id and Password is Invalid...");

            //     }

            //}

            //   con.Close();

            //----------------------------------------------------------

       }

Stored procedure (UPDATE)

 

USE [RegistrationTbl]

GO

/****** Object:  StoredProcedure [dbo].[ProUpdate]    Script Date: 01/24/2021 07:35:29 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE [dbo].[ProUpdate]

@Id int,

@Name nvarchar(50),

@Address nvarchar(50),

@Contact nvarchar(50),

@Email nvarchar(50),

@City nvarchar(50),

@Password nvarchar(50),

@Gender nvarchar(50),

@Hindi nvarchar(50),

@English nvarchar(50),

@Math nvarchar(50),

@Message nvarchar(100)

as

Begin

Update Registration_Table Set Name=@Name,Address=@Address,Contact=@Contact,Email=@Email,City=@City, Password=@Password,Gender=@Gender,Hindi=@Hindi,English=@English,Math=@Math,Message=@Message where Id=@Id;

end;

 

Code:-

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

{

Label Id = (Label)GridView1.Rows[e.RowIndex].FindControl("Label1");

TextBox Name = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1");

TextBox Address = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2");

TextBox Contact = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3");

TextBox Email = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox4");

TextBox City = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox5");

TextBox Password = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox6");

TextBox Gender = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox7");

TextBox Hindi = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox8");

TextBox English = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox9");

TextBox Math = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox10");

TextBox Messasge= (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox11");

string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

SqlConnection con = new SqlConnection(conn_str);

SqlCommand cmd = new SqlCommand("ProUpdate", con);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@Id", Convert.ToInt32(Id.Text));

cmd.Parameters.AddWithValue("@Name", Convert.ToString(Name.Text));

cmd.Parameters.AddWithValue("@Address", Convert.ToString(Address.Text));

cmd.Parameters.AddWithValue("@Contact", Convert.ToString(Contact.Text));

cmd.Parameters.AddWithValue("@Email", Convert.ToString(Email.Text));

cmd.Parameters.AddWithValue("@City", Convert.ToString(City.Text));

cmd.Parameters.AddWithValue("@Password", Convert.ToString(Password.Text));

cmd.Parameters.AddWithValue("@Gender", Convert.ToString(Gender.Text));

cmd.Parameters.AddWithValue("@Hindi", Convert.ToString(Hindi.Text));

cmd.Parameters.AddWithValue("@English", Convert.ToString(English.Text));

cmd.Parameters.AddWithValue("@Math", Convert.ToString(Math.Text));

cmd.Parameters.AddWithValue("@Message", Convert.ToString(Messasge.Text));

       try

            {

                con.Open();

                cmd.ExecuteNonQuery();

                con.Close();

                Response.Write("Updated......");

            }

            catch (Exception Ex)

            {

                Response.Write(Ex.Message);

            }

 

            GridView1.EditIndex = -1;

            show();

        }

 

Delete Store Procedure

---------------------

CREATE PROCEDURE [dbo].[ProDelete]

     @Id int

    

AS

     delete from Registration_Table where Id=@Id;

RETURN 0

Code:

protected void GridView1_RowDeleting(object sender,GridViewDeleteEventArgs e)

    {

Label Id = (Label)GridView1.Rows[e.RowIndex].FindControl("Label1");

string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

            SqlConnection con = new SqlConnection(conn_str);

            SqlCommand cmd = new SqlCommand("ProDelete", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@Id", Convert.ToInt32(Id.Text));

            try

            {

                con.Open();

                cmd.ExecuteNonQuery();

                con.Close();

                Response.Write("Deleted......");

            }

            catch (Exception Ex)

            {

                Response.Write(Ex.Message);

            }

            //  Response.Write(Id.Text);

            show();

        }

Other Events Code:-

protected void Page_Load(object sender, EventArgs e)

        {

            if (!Page.IsPostBack)

            {

                GridView1.AllowPaging = true;

                GridView1.PageSize = 10;

                show();

            }

            if (Session["Email"] == null)

            {  Response.Redirect("LoginSystem.aspx");         }

            else

            {  Label1.Text = (Request.QueryString["Email"]);   }         }

        void show()

        {

            string conn_str = @"Data Source=CSLODHI-PC\SQLEXPRESS;Initial Catalog=RegistrationTbl;Integrated Security=True";

            SqlConnection con = new SqlConnection(conn_str);

            SqlCommand cmd = new SqlCommand();

            cmd.Connection = con;

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.CommandText = "SelectData";

            con.Open();

            // cmd.Parameters.AddWithValue("@id", Convert.ToInt32(TextBox1.Text));

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();

            da.Fill(dt);

            GridView1.DataSource = dt;

            GridView1.DataBind();

            con.Close();

        }

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)

        {

            GridView1.EditIndex = e.NewEditIndex;

            show();

        }

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)

        {

            GridView1.EditIndex = -1;

            show();

        }

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

        {

            GridView1.PageIndex = e.NewPageIndex;

            show();

        }

 

 

 

 

Validation with Registrationform

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="StoreProcedured.Registration" UnobtrusiveValidationMode="None"%>

 

<form id="form1" runat="server">

    <div>

            <table class="auto-style1">

            <tr>

                <td class="auto-style2">Name</td>

                <td>

<asp:TextBox ID="TextBox1" runat="server" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style5">

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Name is Required." ForeColor="#FF3300"></asp:RequiredFieldValidator>

                </td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">Address</td>

                <td>

<asp:TextBox ID="TextBox2" runat="server" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style5">

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" Display="Dynamic" ErrorMessage="Please Enter Address" ForeColor="Red" ViewStateMode="Enabled">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style3">Contact No.</td>

                <td class="auto-style4">

                    <asp:TextBox ID="TextBox3" runat="server" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style6">

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3" Display="Dynamic" ErrorMessage="Contact no is required." ForeColor="Red">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style6">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">Email</td>

                <td>

<asp:TextBox ID="TextBox4" runat="server" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style5">

<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox4" Display="Dynamic" ErrorMessage="Email is required." ForeColor="Red">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style5">

                    &nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">City</td>

                <td>

<asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="137px">

                        <asp:ListItem>Vidisha</asp:ListItem>

                        <asp:ListItem>Bhopal</asp:ListItem>

                        <asp:ListItem>Indore</asp:ListItem>

                    </asp:DropDownList>

                </td>

                <td class="auto-style5">

                    &nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style7">Password</td>

                <td class="auto-style8">

<asp:TextBox ID="TextBox5" runat="server" TextMode="Password" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style9">

<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TextBox5" Display="Dynamic" ErrorMessage="Password is Requried." ForeColor="Red">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style9"></td>

            </tr>

            <tr>

                <td class="auto-style2">Gender</td>

                <td>

<asp:RadioButton ID="RadioButton1" runat="server"GroupName="G" Text="Male" />

<asp:RadioButtonID="RadioButton2"runat="server"GroupName="G" Text="Female" />

             </td>

                <td class="auto-style5">

<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" ErrorMessage="Please Select Gender." ForeColor="Red" OnServerValidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>

                </td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">Subject</td>

                <td>

<asp:CheckBox ID="CheckBox1" runat="server" Text="Hindi" />

<asp:CheckBox ID="CheckBox2" runat="server" Text="English" />

<asp:CheckBox ID="CheckBox3" runat="server" Text="Math" />

                </td>

                <td class="auto-style5">&nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">Message</td>

                <td>

<asp:TextBox ID="TextBox6" runat="server" Height="87px" TextMode="MultiLine" Width="299px"></asp:TextBox>

                </td>

                <td class="auto-style5">

<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="TextBox6" Display="Dynamic" ErrorMessage="Message is required." ForeColor="Red">*</asp:RequiredFieldValidator>

                </td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

            <tr>

                <td class="auto-style2">&nbsp;</td>

                <td>&nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

          

            <tr>

                <td class="auto-style2">&nbsp;</td>

                <td style="text-align: center">

                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />

                </td>

                <td class="auto-style5">&nbsp;</td>

                <td class="auto-style5">&nbsp;</td>

            </tr>

        </table>   </div>     </form>

Validation with Registrationform Validation with Registrationform Reviewed by JOB ORIENTED STUDY ACADEMY on February 02, 2021 Rating: 5

No comments:

Powered by Blogger.