Friend Suggestions People You May Know in Social Networking Website using asp.net csharp


People You May Know in Social Networking Website using asp.net csharp


  1. Facebook also have a Control which shows and keeps on giving friend suggestions so that we can expand our social network and make more friends.
  2. We have also developed a user control which gives suggestions about the people you may know

PeopleYouMayKnow.ascx Code:

  1. Open PeopleYouMayKnow.ascx User Control Which You have created in Controls Folder. 
  2.  In the Source of PeopleYouMayKnow.ascx user control you can add the following piece of code given below.
  3. In this User control we have a datalist which is showing all the people who are not in your friends list

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PeopleYouMayKnow.ascx.cs"
    Inherits="Controls_PeopleYouMayKnow" %>
<style type="text/css">
    .FriendsSuggestions
    {
        width: 130px;
        text-align: center;
    }
    .FriendsSuggestionsTD
    {
        height: 20px;
    }
</style>
<table align="center" cellpadding="0" cellspacing="0" class="FriendsSuggestions">
    <tr>
        <td align="center" class="FriendsSuggestionsTD">
            <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="X-Small"
                Text="People You May Know"></asp:Label>
        </td>
    </tr>
    <tr>
        <td align="center">
            <asp:DataList ID="dlProfile" runat="server" BorderColor="Black" BorderStyle="Ridge"
                BorderWidth="0px" Visible="true" Width="100px">
                <ItemTemplate>
                    <table align="center" cellspacing="1" style="width: 100%">
                        <tr>
                            <td align="center">
                                <asp:ImageButton ID="ImagePeopleYouMayknow" runat="server" 
                                BorderColor="Black" BorderStyle="Ridge"
                                BorderWidth="1px" Height="63px" 
                                ImageUrl='<%# "ImageHandler.ashx?RegisterId="+ Eval("RegisterId") %>'
                                Width="74px" OnClick="ImagePeopleYouMayknow_Click" 
                                CommandArgument='<%#Bind("RegisterId") %>' />
                            </td>
                        </tr>
                        <tr>
                            <td align="center">
                                <asp:Label ID="lblName" runat="server" Font-Size="Small" Text='<%# Bind("Name") %>'
                                    ForeColor="Black"></asp:Label>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:DataList>
        </td>
    </tr>
    <tr>
        <td align="center">
             
        </td>
    </tr>
</table>

    

PeopleYouMayKnow.ascx.cs C# Code:

  1. Open PeopleYouMayKnow.ascx User Control Which You have created in Controls Folder.
  2.  In the Source of PeopleYouMayKnow.ascx user control you can add the following piece of code given below.
  3. In the code behind we are calling a Method PeopleYouMayKnow() which is getting all the friends who you may know based on some query.
  4. Finally we are binding all the records to datalist.We have written a query with sub query and union of friends and register tables

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 Controls_PeopleYouMayKnow : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
         PeopleYouMayKnow();
    }

    private void PeopleYouMayKnow()
    {
        DataTable dt = new DataTable();
        string query = "Select * from Register R where RegisterId not in ((select F.FriendId as RegisterId  from Friends f where f.MyId='" + Session["UserId"] + "' and f.Status=1) Union  (select F.MyId as RegisterId  from Friends f where f.FriendId='" + Session["UserId"] + "' and f.Status=1))and R.RegisterId !='" + Session["UserId"] + "'";

        dt = Database.GetData(query);
        if (dt.Rows.Count > 0)
        {
            
            dlProfile.Visible = true;
            dlProfile.DataSource = dt;
            dlProfile.DataBind();
        }
        else
        {

        }
    }
    protected void ImagePeopleYouMayknow_Click(object sender, ImageClickEventArgs e)
    {
        Session["CurrentProfileId"] = (((ImageButton)sender).CommandArgument).ToString();
        Response.Redirect("Main.aspx");
    }
}


2 comments:

  1. i have an problem when the above code is compiled in database class getdata method
    in fill method error like incorrect syntax near ",' how it can be solve plz help me

    ReplyDelete