Thursday, 3 November 2016

// // Leave a Comment

How to send forget password on registered email id in asp.net c#

Sent a mail to the user‘s email id with his forgotten password .we have a database where we fetch the email id and password and send a email with the password.

For more:send forgot password link on email for reset in asp.net C# ,Login page in asp.net c# with sql database , Pop up login page in asp.net c# using CSS and java script.


SQL server:-

Script:-
CREATE DATEBASE[CodeSolution]

USE [CodeSolution]
GO

/*************/

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[record](
          [record_id] [int] IDENTITY(1,1) NOT NULL,
          [Name] [nvarchar](50) NULL,
          [Contact_no] [nvarchar](50) NULL,
          [Email] [nvarchar](50) NULL,
          [Password] [nvarchar](50) NULL,
 CONSTRAINT [PK_record] PRIMARY KEY CLUSTERED
(
          [record_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  =OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON,ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Source Code:-

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

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <fieldset style="width: 350px;" align="center">
        <legend>Send Forget Password In Registerd Email </legend>
        <asp:TextBox ID="txtemail" runat="server" Width="199px"Placeholder="Enter Your Registed Email ID"></asp:TextBox><br />
        <br />
        <asp:Button ID="Button1" runat="server"OnClick="Button1_Click" Text="Submit" Width="78px" />
        <br />
        <asp:Label ID="lbresult" runat="server" Text=""></asp:Label>
    </fieldset>
    </form>
</body>
</html>


Code behind(C#):-

using System;
using System.Data.SqlClient;
using System.Data;
using System.Net.Mail;


using System.Net;
using System.Drawing;

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

{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=NEERAJ-PC;Initial Catalog=CodeSolution;Persist Security Info=True;User ID=sa; password=12345678");
        con.Open();
        SqlCommand cmd = new SqlCommand("SELECT Email,Password FROM record Where Email= '" + txtemail.Text + "'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        if (ds.Tables[0].Rows.Count > 0)
        {
            MailMessage email = new MailMessage();
            email.From = new MailAddress(txtemail.Text); //Enter sender email address
            email.To.Add(txtemail.Text); //Destination Recipient e-mail address.
            email.Subject = "Your Forget Password From Code Solutions";//Subject for your request
            email.Body += "Hi,<br/>Your Email ID is: " + ds.Tables[0].Rows[0]["Email"] + "<br/><br/>Your Password is: " + ds.Tables[0].Rows[0]["Password"] + "<br/> <br/> Thanks <br/> Code Solutions";
            email.IsBodyHtml = true;
            //SMTP SERVER DETAILS
            SmtpClient smtpc = new SmtpClient("smtp.gmail.com");
            smtpc.Port = 587;
            smtpc.UseDefaultCredentials = false;
            smtpc.EnableSsl = true;
            smtpc.Credentials = newNetworkCredential("hmclko@gmail.com""9450216522");
            smtpc.Send(email);
            lbresult.Text = "Your Password Has Been Sent To Your Email ID";
            lbresult.ForeColor = Color.Green;
           
        }
        else
        {

            lbresult.Text = "Please Enter Correct Email ID";
            lbresult.ForeColor = Color.Red;

        }


        txtemail.Text = "";
    }

}

Read More
// // Leave a Comment

how to get second height salary in Sql Server

select max(salary) from EMP where salary <(select max (salary)from EMP)
Read More
// // Leave a Comment

How to set Gridview column width dynamically in Asp.Net C#

How to set column- width of gridview in asp.net .We can use several methods to achieve it just like source code (grid view property), code behind(C#) and CSS.


First Method:-
we can set the columns width by using ItemStyle-Width property just like below :-

<asp:GridView ID="GridView1" runat="server"AutoGenerateColumns="false">
            <Columns>
                <asp:BoundField DataField="Name" HeaderText="Name"ItemStyle-Width="50px" />
                <asp:BoundField DataField="Contactno"HeaderText="Contactno" ItemStyle-Width="50px" />
                <asp:BoundField DataField="Brithday"HeaderText="Brithday" ItemStyle-Width="50px" />
            </Columns>
        </asp:GridView>

Second Method:-
We can call the columns’s width from code behind just like below :-
For this code we need to need to call RowDataBound.
protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            GridView1.Columns[0].ItemStyle.Width = 50;
            GridView1.Columns[1].ItemStyle.Width = 50;
            GridView1.Columns[2].ItemStyle.Width = 50;
        }

    }
Third method:-
We can set the column width using css but we call this call on only code behind because we can not directly call the css in column from source code and if we call on this gridview then it will be set whole gridview width not the columns. We can use this method like below:-
Source code:-

 <style type="text/css">
        .columnwidth
        {
            width50px;
        }
  </style>

Codebehind:-

protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            for (int i = 0; i > e.Row.Cells.Count; i++)
            {
                e.Row.Cells[i].CssClass = "columnwidth";
            }
        }
    }

Read More
// // Leave a Comment

Menu Bar with CSS in ASP .NET C#

Source code:-

<!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></title>
  <style type="text/css">
        #cssmenu ul
        {
            margin: 0;
            padding: 0;
            list-style-type: none;
            position: relative;
            display: block;
            height: 36px;
            text-transform: uppercase;
            font-size: 12px;
            font-weight: bold;
            background: transparent url('image/img (3).gif') repeat-x top left;
            font-family: Helvetica, Arial, Verdana, sans-serif;
            border-bottom: 4px solid #004c99;
            border-top: 1px solid #74b0c6;
            width: auto;
        }
        #cssmenu li
        {
            display: block;
            float: left;
            margin: 0;
            padding: 0;
        }
        #cssmenu li a
        {
            display: block;
            float: left;
            color: #6d7078;
            text-decoration: none;
            font-weight: bold;
            padding: 12px 20px 0 20px;
            height: 24px;
            background: transparent url('image/img (1).gif') no-repeat top right;
        }
        #cssmenu li a:hover
        {
            background: transparent url('image/img (2).gif') no-repeat top right;
            color: #6d7078;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id='cssmenu'>
                        <ul>
                            <li><a href='index.html'><span>Home </span></a></li>
                            <li><a href='about.html'><span>About Us</span></a></li>
                            <li><a href='career.html'><span>Career </span></a></li>
                            <li class='last'><a href='contact.html'><span>Contact Us</span></a></li>                           
                        </ul>
                    </div>
</form>
</body>
</html>
Read More