CODE
static string username = string.Empty;
static string Fusername = string.Empty;
private string constring = ConfigurationManager.ConnectionStrings["CONN"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Populatebooks();
}
}
private void Populatebooks()
{
// string userId = Session["UserId"].ToString();
username = this.Page.User.Identity.Name;
//string userId = Session["UserId"].ToString();
string getADPOST = "GetPEOPLE";
using (SqlConnection con = new SqlConnection(constring))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(getADPOST, con))
{
cmd.CommandType = CommandType.StoredProcedure;
{
cmd.Parameters.AddWithValue("@UserName", username);
// cmd.Parameters.AddWithValue("@FriendUserName", Fusername);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
Getpeopleyoumayknow.DataSource = dt;
Getpeopleyoumayknow.DataBind();
}
}
}
}
protected void People(object sender, EventArgs e)
{
DataListItem item = (sender as LinkButton).NamingContainer as DataListItem;
// int bookId = Convert.ToInt32((item.FindControl("lblId") as Label).Text);
// string Name = ((item.FindControl("lblname") as Label).Text);
string usernameFollow = ((item.FindControl("lblId") as Label).Text);
// string fuserName = ((item.FindControl("lblfriendusername") as Label).Text);
string userStatus = ((item.FindControl("lblUserStatus") as Label).Text);
string count = ((item.FindControl("lblcount") as Label).Text);
//string status = ((item.FindControl("lblstatus") as Label).Text);
// int bookId = Convert.ToInt32((item.FindControl("lblname") as Label).Text);
using (SqlConnection con = new SqlConnection(constring))
{
if ((item.FindControl("btnLike") as LinkButton).Text.ToUpper() == "FOLLOW")
using (SqlCommand cmd = new SqlCommand("INSERT INTO FollowStatus2 values(@UserName,@UserStatus,@Count)", con))
{
// cmd.Parameters.AddWithValue("@UserId", Session["UserId"]);
// cmd.Parameters.AddWithValue("@BookId", bookId);
cmd.Parameters.AddWithValue("@UserName", username = this.Page.User.Identity.Name);
//cmd.Parameters.AddWithValue("@FriendUserName", username);
cmd.Parameters.AddWithValue("@UserStatus", "TRUE");
cmd.Parameters.AddWithValue("@Count", 1);
// cmd.Parameters.AddWithValue("@Status", status);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
this.Populatebooks();
}
protected void Getpeopleyoumayknow_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// string bookid = (e.Item.FindControl("lblId") as Label).Text;
// string Name = (e.Item.FindControl("lblname") as Label).Text;
string usernamefollow = (e.Item.FindControl("lblId") as Label).Text;
// string fUserName = (e.Item.FindControl("lblfriendusername") as Label).Text;
// string userStatus = (e.Item.FindControl("lblUserStatus") as Label).Text;
// string bookid = (e.Item.FindControl("lblId") as Label).Text;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT f.FriendUserName AS username,fav.Name,'Following' [Status] FROM FollowStatus f INNER JOIN User3 fav On f.UserName = fav.UserName WHERE fav.UserName=@FriendUserName", con))
{
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("@UserName", username = this.Page.User.Identity.Name);
cmd.Parameters.AddWithValue("@FriendUserName", username);
sda.Fill(dt);
foreach (DataRow row in dt.Rows)
{
if (usernamefollow == row["username"].ToString())
{
(e.Item.FindControl("btnLike") as LinkButton).Text = "Following";
// (e.Item.FindControl("lblmark") as Label).Text = "";
}
}
}
}
}
TABLE TO INSERT IT
------------------------------------------------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[FollowStatus](
[Id] [int] IDENTITY(1,1) NOT NULL,
[UserName] [varchar](50) NULL,
[FriendUserName] [varchar](50) NULL,
[UserStatus] [bit] NULL,
[Count] [int] NULL,
CONSTRAINT [PK_FollowStatus] PRIMARY KEY CLUSTERED
(
[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
SET ANSI_PADDING OFF
GO
SELECTING THE USERS USERNAMES
---------------------------------
CREATE PROC [dbo].[GetPEOPLE]
@UserName VARCHAR (200)
AS
BEGIN
SELECT u.UserName,u.ImageName,u.Name,u.Country FROM User3 u ORDER BY u.RegisterdDate DESC
END
GO
HTML MARKUPS
<div class="">
<asp:DataList ID="Getpeopleyoumayknow" runat="server" CssClass=" table table-bordered table-striped table-hover" OnItemDataBound="Getpeopleyoumayknow_ItemDataBound">
<ItemTemplate>
<!-- Conversations are loaded here -->
<div class="">
<!-- Message. Default to the left -->
<div class="" style=" margin-left:4px; margin-right:4px">
<div class=" " style="">
<ul class="media-list " style="margin-bottom:0px; margin-top:0px">
<li class="media">
<a class="pull-left " href='<%#getUserHREF1(Container.DataItem)%>'>
<img src='<%#getSRC(Container.DataItem)%>' class="media-object img-rounded animated fadeInDown" style=" width:80px; height:80px; " />
</a>
<div class="media-body">
<div class="media-heading" style="">
<div style=" ">
<a class="pull-left" href='<%#getUserHREF1(Container.DataItem)%>'>
<asp:Label ID="lblname" runat="server" Text='<%# Eval("Name") %>' />
<div class="clearfix"></div>
<asp:Label ID="lblId" Text='<%#Eval("UserName") %>' Visible="false" runat="server" />
<asp:Label ID="lblUserStatus" Visible="false" runat="server" />
<asp:Label ID="lblcount" Visible="false" runat="server" />
<asp:Label ID="lblstatus" Visible="false" runat="server" />
<div class="clearfix"></div>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("Country") %>' Font-Bold="True " ForeColor="" Font-Size="" Visible="true " />
<div class="pull-right" >
<asp:LinkButton ID="btnLike" runat="server" CssClass="btn btn-default" ToolTip="Appreciate" Font-Size="Small" Width="" OnClick="People">
<asp:Label ID="Label3" runat="server" CssClass="fa fa-user-plus" ToolTip="Like" Font-Size="Small" ForeColor="#0099FF"></asp:Label> <i class="" style="margin-right:1px" ></i>
<asp:Label ID="Label1" runat="server" Text="Follow"></asp:Label>
</asp:LinkButton>
<asp:Label ID="lblmark" runat="server" Text="Label" Visible="False"></asp:Label>
</div>
</a>
<div class="clearfix"></div>
<div style=" ">
</div>
</div>
</div>
<!-- Nested media object -->
</div>
</li>
</ul>
</div>
</div><!--/.direct-chat-messages-->
<!-- Contacts are loaded here -->
</div><!-- /.box-body -->
</ItemTemplate>
</asp:DataList>
</div>