Hima

Hima

  • NA
  • 26
  • 4.3k

how to count the clicks of an image?

Feb 24 2014 1:24 AM
hi Gudmrng..
I Am fresher to .Net, I have a doubt that, in my website i have to display the no.of people clicking on the like image for the conversation!!!!. I used repeater to display the conversation. Plzzz anyone Helpme.... Here Im attaching my code and stored procedure.

Source View:
<div align="center">
<asp:Repeater ID="RepDetails" runat="server" onitemcommand="RepDetails_ItemCommand">
<HeaderTemplate>
<table style=" border:1px solid #df5015; width:500px" cellpadding="0">
<tr style="background-color:#df5015; color:White">
<td colspan="1">
<b>Comments</b>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#EBEFF0">
<td>
<table style="background-color:#EBEFF0;border-top:1px dotted #df5015; width:500px" >
<%--<tr>
<td>
Subject:
<asp:Label ID="lblSubject" runat="server" Text='<%#Eval("Subject") %>' Font-Bold="true"/>
</td>
</tr>--%>
</table>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblComment" runat="server" Text='<%#Eval("Comment") %>'/>
</td>
</tr>
<tr>
<td>
<table style="background-color:#EBEFF0;border-top:1px dotted #df5015;border-bottom:1px solid #df5015; width:500px" >
<tr>
<td><asp:ImageButton ID="imgbtnlike" runat="server" ImageUrl="~/image/like.png" Height="20" Width="20" CommandName="imgbtnlike"/>&nbsp;<asp:Label ID="lblcount" runat="server"></asp:Label><asp:Label ID="lbllike" runat="server" text="Like"></asp:Label></td>
<td>Event: <asp:Label ID="lblUser" runat="server" Font-Bold="true" Text='<%#Eval("EventID") %>'/></td>
<td>Created Date:<asp:Label ID="lblDate" runat="server" Font-Bold="true" Text='<%#Eval("DateTime") %>'/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>








CodeView:


protected void RepDetails_ItemCommand(object source, RepeaterCommandEventArgs e)
{
ImageButton imglike = sender as ImageButton;
Repeater RepDetail1 = (Repeater)imglike.NamingContainer;
Label lbllike = (Label)RepDetail1.FindControl("lblcount");
lblcount = lbllike.Text;
try
{
con.Open();
SqlCommand cmd = new SqlCommand("usp_likecount", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.Parameters.AddWithValue("@EventID", lblID.Text);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
RepDetails.DataSource = ds;
RepDetails.DataBind();
}



Stored Procedure:



USE [*****]
GO
/****** Object: StoredProcedure [dbo].[usp_likecount] Script Date: 02/24/2014 11:38:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_likecount]
(@EventID int
,@EvenConvID int)
AS
BEGIN
DECLARE @like int
SELECT @like=Likes FROM EventConv WHERE EventID=@EventID AND EvenConvID=@EvenConvID
UPDATE EventConv SET [Likes]=@like+1 WHERE EvenConvID=@EvenConvID
END




Answers (21)