On-line Address Book in ASP.NET 2.0

0 comments


This is an On-line Address Book project. Those who are new to ASP.NET or going for first project can learn a lot from this. This is a project to keep the address and other information. In our daily life we meet many people and we have to keep the information and addresses of these people. This project is very useful to keep the record.

To use this project just change the connection string. Store the database in ZipFile.

Welcome.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Welcome.aspx.cs" Inherits="Welcome" %>
<!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>Welcome</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <table  width="100%" background="BackGround.jpg">
        <tr><td align="center">
              <asp:Label ID="lblWelcome" runat="server"
                   Text="Welcome In On Line Address Book" Font-Bold="true"
                    
 Font-Size="22pt" ForeColor="#6600ff"></asp:Label>
            </td></tr>
            <tr><td>&nbsp;</td></tr>
            <tr><td align="center">
                  <asp:Label ID="lblDoAddress" runat="server" Text="Do Your Address On Line" Font-Bold="true"
                         ForeColor="#33cccc"  Font-Size="14pt"></asp:Label>
                 </td></tr>
            <tr><td height="50px">&nbsp;</td></tr>
            <tr><td align="center">
                  <asp:ImageButton ID="Imgm" ImageUrl="~/case2-a.gif" runat="server"OnClick="StartAddress" />
                </td></tr>
            <tr><td>&nbsp;</td></tr>
            <tr><td align="center">
                  <asp:Label ID="lblAddress" runat="server" Text="(Address Book)" Font-Bold="true"ForeColor="#000099"
                            Font-Size="16pt"></asp:Label>
                </td></tr>
            <tr><td height="190px"></td></tr>
            <tr><td>&nbsp;&nbsp; &nbsp;&nbsp; <asp:Button ID="btnAddressBook" runat="server"
                            Text="Go Inside The Address Book" BackColor="#ff9900" Height="45px"OnClick="btnInside_Click" />
            </td></tr>
          
      </table>
      <table background="BackGround.jpg" cellpadding="0" cellspacing="0" width="100%">
        <tr><td align="right">
              <asp:Label ID="lblName" runat="server" Text="Rahul Saxena" Font-Bold="true" Font-Size="16pt"
                 ForeColor="#6600ff"></asp:Label><br /><br />
              <asp:Label ID="lblEmail" runat="server" Text="Email: 14rahulsaxena@gmail.com"
                Font-Bold="true"  Font-Size="14pt" ForeColor="#6600ff"></asp:Label>
            </td><td width="5%"></td></tr>
        <tr><td Height="43px"></td></tr>
      </table>   
    </div>
  </form>
</body>
</html>

Welcome.aspx.cs is:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Welcome : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnInside_Click(object sender, EventArgs e)
    {
        Response.Redirect("AllRecord.aspx");
    }
    protected void StartAddress(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("AllRecord.aspx");
    }
}

AllRecord.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AllRecord.aspx.cs"  Inherits="AllRecord" %>
<!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>All Record</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <table cellpadding="0" cellspacing="0" width="90%" border="0" height="100%">
        <tr><td width="10px"></td><td><asp:Image ID="imageContact" runat="server"  ImageUrl="~/clip1-c.gif"/> </td></tr>
        <tr><td width="10px"></td><td width="90%"  background="BackGround.jpg" align="left">
              <asp:Button ID="btnSubmit" runat="server" Text="Add New Address" OnClick="btnSubmit_Click" />
                          
&nbsp; &nbsp; &nbsp; &nbsp;
              
<asp:Button ID="btnSearch"  runat="server" Text="Search A Address"  OnClick="SearchRecord" />
                            
&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp; &nbsp;
              <asp:Image ID="ImgMove" runat="server" ImageUrl="~/ball1-a.gif" />
              <asp:Label ID="lblSearch" Text="All Address" runat="server" Font-Bold="true"  ForeColor="#ff6600"
                         
 Font-Size="16pt"> </asp:Label>
                 &nbsp; &nbsp; &nbsp; &nbsp;
             <asp:Image ID="ImgDate" runat="server" ImageUrl="~/hourglass-b.gif" />
             <asp:Label ID="lblShowTime" runat="server" Text="Date" Font-Bold="true"> </asp:Label>
                    
&nbsp; &nbsp;
             <asp:Label ID="lbltime" runat="server"></asp:Label>
           </td></tr>
        <tr><td height="5px"></td></tr>
        <tr><td width="10px"></td>
             <td><table background="BackGround.jpg"  cellpadding="0" cellspacing="0" height="100%" border="0"  width="100%">
                   <tr><td height="25px"></td></tr>
                   <tr><td width="10px"></td><td align="center" >
                         <asp:DataGrid ID="GridAllRecord" runat="server"  AutoGenerateColumns="false" Width="90%"
                              DataKeyField="ID"
                                PagerStyle-HorizontalAlign="Center"  BorderStyle="ridge" GridLines="Both"
                                BorderWidth="2px" BorderColor ="white" BackColor="white" CellPadding="3" CellSpacing="1"
                                OnEditCommand="EditAddress"  OnDeleteCommand="AddressDelete"
                                OnItemCommand="Grid_ItemCommand" AllowSorting="true" PageSize=5
                                OnPageIndexChanged="GridAllRecord_PageIndexChanged" AllowPaging="true">
                         <FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
                         <HeaderStyle Font-Bold="True" ForeColor="#FFFFFF" BackColor="#A53A6A"></HeaderStyle>
                         <FooterStyle BackColor="beige" />
                         <PagerStyle Font-Bold="true" Mode=NumericPages Font-Underline="true"/>
                         <Columns>
                           <asp:BoundColumn DataField=ID HeaderText="ID" Visible="false">
                             <ItemStyle BackColor="graytext" />
                             <HeaderStyle BackColor="graytext" />
                           </asp:BoundColumn>
                       
                           <asp:TemplateColumn HeaderText="First Name">
                             <ItemTemplate>
                               <asp:LinkButton ID="lnkName" runat="server"  Text='<%#DataBinder.Eval
                                   (Container.DataItem,"FirstName") %>' CommandName="RecordShow"> </asp:LinkButton>
                             </ItemTemplate>
                           </asp:TemplateColumn>           
                          
                           <asp:BoundColumn DataField=LastName HeaderText="Last Name">
                             <ItemStyle BackColor=GhostWhite />
                           </asp:BoundColumn>               
                          
                           <asp:BoundColumn DataField=PersonelEmail HeaderText="Personnel(EMail)">
                             <ItemStyle BackColor=GhostWhite />
                           </asp:BoundColumn>         
                          
                           <asp:BoundColumn DataField=Mobile HeaderText="Mobile">
                             <ItemStyle BackColor=GhostWhite />
                           </asp:BoundColumn>   
                             
                           <asp:EditCommandColumn EditText="Edit Address" HeaderText="Edit Address">
                 </asp:EditCommandColumn>      
                           <asp:ButtonColumn  CommandName="DeleteAddress" HeaderText="Delete Address"
                                  Text="Delete"></asp:ButtonColumn>
                         </Columns>   
                      </asp:DataGrid>
                    </td>
                  </tr>
                <tr><td height="25px"></td></tr>
              </table></td></tr>
           <tr><td height="15px"></td></tr>
         <%-- <tr><td width="10px"></td><td><asp:Label ID="lblTotalRegisterartion" runat="server"
                   Text="Total Registered Address :"></asp:Label><asp:Label ID="lblRegistered"    
                                                 runat="server"></asp:Label></td></tr>--%>
       </table>   
     </div>
    </form>
  </body>
</html>

AllRecord.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class AllRecord : System.Web.UI.Page
{
    string connect = @"Data Source=MCN0100;Initial Catalog=AddressBook; Uid=sa; Pwd=";
    SqlConnection con;
    SqlCommand cmd = new SqlCommand();
    SqlDataAdapter da;
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rebind();
            string Time = DateTime.Now.Date.ToShortDateString();
            lbltime.Text = Time;
            //TotalUsers();
        }
    }

    public void rebind()
    {
        con = new SqlConnection(connect);
        cmd.CommandText = "select ID,FirstName,LastName, Mobile, PersonelEmail from record";
        da = new SqlDataAdapter(cmd);
        cmd.Connection = con;
        da.Fill(ds);
        con.Open();
        cmd.ExecuteNonQuery();
        GridAllRecord.DataSource = ds;
        GridAllRecord.DataBind();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Response.Redirect("Register.aspx");
    }

    protected void Grid_ItemCommand(object sender, DataGridCommandEventArgs e)
    {
        if (e.CommandName == "RecordShow")
        {
            int Rep_Id = int.Parse(e.Item.Cells[0].Text);
            Session["ID"] = Rep_Id;
            Response.Redirect("ShowSelectedRecord.aspx");
        }
        if (e.CommandName == "DeleteAddress")
        {
            con = new SqlConnection(connect);
            int UpadteAddress = int.Parse(e.Item.Cells[0].Text);
            cmd.CommandText = "delete from Record where ID=" + UpadteAddress;
            cmd.Connection = con;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();          
            GridAllRecord.EditItemIndex=-1;
            rebind();                   
        }
    }

    protected void SearchRecord(object sender, EventArgs e)
    {
        Response.Redirect("Search.aspx");
    }

    public void GridAllRecord_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        GridAllRecord.CurrentPageIndex = e.NewPageIndex;
        rebind();
    }

    public void EditAddress(object ssender, DataGridCommandEventArgs e)
    {
        int UpadteAddress = int.Parse(e.Item.Cells[0].Text);
        Session["UpadteAddressID"] = UpadteAddress;
        Response.Redirect("LoginCheck.aspx");
    }

    public void AddressDelete(object sender, DataGridCommandEventArgs e)
    {
        con = new SqlConnection(connect);
        int UpadteAddress = int.Parse(e.Item.Cells[0].Text);
        cmd.CommandText = "delete from Record where ID=" + UpadteAddress;
        cmd.Connection = con;
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();      
        GridAllRecord.EditItemIndex=-1;
        rebind();
    }


    //public void TotalUsers()
    //{
    //    con = new SqlConnection(connect);
    //    cmd.CommandText = "select  *  from Record";
    //    da = new SqlDataAdapter(cmd);
    //    da.Fill(ds);
    //    cmd.Connection = con;
    //    con.Open();
    //    cmd.ExecuteNonQuery();
    //    int TotalUser = int.Parse(ds.Tables[0].Rows.Count.ToString());
    //    lblRegistered.Text = TotalUser.ToString();
    //    con.Close();
    //}
}

READ MORE >>

0 comments: