About Me in Social Networking Website like Facebook using asp.net csharp



About Me in Social Networking Website like Facebook using asp.net csharp(c#)



  • About Me Page as the name suggests it shows the information provided by the user at the time of registration on HearBeat Project.
  • It shows general information like Name,Emailid,Gender,date of birth,Country and a short sentence about the user.
  • It Generally Fetches the Information about the User who is Currently Logged in and It also shows the information about the Current Profile User.
  • For Example:Currently i am looking at my friends profile and when i click on about me link it will show my friends aboutme and when i am on my profile then it shows my information

AboutMe.aspx Code:

  • Open AboutMe.aspx page.In the Source of aboutme.aspx page you can make a tabular structure as shown in below code snippet.
  • Design Explanation:
  • Inside the Content place holder of AboutMe.aspx we have made a tabular structure as shown in the code snippet.
  • Inside One td we have dragged dropped one Datalist and Inside Datalist we have again made a tabular structure to show the user information in proper manner.We have named the datalist as ListAboutMe
  • We have Binded the User Information using DataBinder.Eval(Container.DataItem, "FieldName") Evaluation Function


<%@ Page Title="" Language="C#" MasterPageFile="~/ProfileMaster.master" AutoEventWireup="true"
    CodeFile="AboutMe.aspx.cs" Inherits="AboutMe" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table cellspacing="1" class="style2">
        <tr>
            <td align="center" style="width: 280px">
                 
            </td>
            <td align="left">
                 
            </td>
        </tr>
        <tr>
            <td align="center" colspan="2">
                <hr />
                <asp:DataList ID="ListAboutMe" runat="server">
                    <ItemTemplate>
                        <table cellspacing="1" style="width: 432px">
                            <tr>
                                <td align="center" style="width: 183px">
                                     
                                </td>
                                <td align="center">
                                     
                                </td>
                            </tr>
                            <tr>
                                <td align="center" style="width: 183px">
                                    Name
                                </td>
                                <td align="left">
                                    <%# DataBinder.Eval(Container.DataItem, "Name")%>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" style="width: 183px">
                                    EmailId
                                </td>
                                <td align="left">
                                    <%# DataBinder.Eval(Container.DataItem, "EmailId")%>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" style="width: 183px">
                                    Date Of Birth
                                </td>
                                <td align="left">
                                    <%# DataBinder.Eval(Container.DataItem, "DOB")%>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" style="width: 183px">
                                    Country
                                </td>
                                <td align="left">
                                    <%# DataBinder.Eval(Container.DataItem, "Country")%>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" style="width: 183px">
                                    Gender
                                </td>
                                <td align="left">
                                    <%# DataBinder.Eval(Container.DataItem, "Gender")%>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" style="width: 183px">
                                    AboutMe
                                </td>
                                <td align="left">
                                    <%# DataBinder.Eval(Container.DataItem, "AboutMe")%>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" style="width: 183px">
                                     
                                </td>
                                <td align="center">
                                     
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:DataList>
                <hr />
            </td>
        </tr>
        <tr>
            <td align="center" style="width: 280px">
                 
            </td>
            <td align="left">
                 
            </td>
        </tr>
        <tr>
            <td align="center" style="width: 280px">
                 
            </td>
            <td align="left">
                 
            </td>
        </tr>
    </table>
</asp:Content>

AboutMe.aspx.cs C# Code:

  • Now Open AboutMe.aspx.cs file.In the Code behind file of AboutMe.aspx you can write the following piece of code.
  • Code Explanation:
  • From the Page_Load Method we are calling a Function which we have named as GetAboutMe().
  • In GetAboutMe() Function we have created a new Datatable Object and after that we are writing a query the get all the information of the user whose RegisterId is CurrentPofileId which is stored in session. 
  • We have Used the Database.GetData() Function which we have created in Database Connectivity Part of this project.Database.cs is a static class and it contains static function GetData() so we can call it from anywhere in our project without even creating an object of it and it returns datatable
  • Finally we are checking whether there are any records for the current user.If records are there then we are binding it to datalist ListAboutMe


        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;
        using System.Web.UI;
        using System.Web.UI.WebControls;
        using System.Data;

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

           private void GetAboutMe()
           {
                DataTable dt = new DataTable();
 string query = "select  *  from Register where RegisterId='" + Session["CurrentProfileId"] + "'";
                dt = Database.GetData(query);
                if (dt.Rows.Count > 0)
                {
                    ListAboutMe.DataSource = dt;
                    ListAboutMe.DataBind();
                }
            }
        }

    


1 comments:

  1. Hi i have problem with the code at dt = Database.GetData(query); the error is Database what should i do here ? dt = Database.GetData(query); error The name 'Database' does not exist in the current context

    ReplyDelete