显示标签中的点击次数! [英] display the click count in label!

查看:75
本文介绍了显示标签中的点击次数!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在标签中显示点击图像的计数值(例如:在Facebook中),所以我写了存储过程来增加值,同时我的代码在转发器下,

这里我的问题是我得到一个错误,因为IListSource不包含任何数据源Plz帮助我...这里我附上我的代码。





源代码:

 <  < span class =code-leadattribute> asp:Repeater     ID   =  RepDetails    runat   =  server    onitemcommand   =  RepDetails_ItemCommand <小号pan class =code-keyword>>  
< HeaderTemplate >
< table style = border:1px solid#df5015; width:500px cellpadding = 0 >
< ; tr style < span class =code-keyword> = background-color:#00CC66;颜色:白色 >
< td colspan = 1 align < span class =code-keyword> = center >
评论
< / td >
< / tr >
< / HeaderTemplate < span class =code-keyword>>
< itemtemplate >
< tr < span class =code-attribute> style = background-color:#00CC66 >
< td >
< 样式 = background-color:#EBEFF0; border-removed1px dotted#df5015;宽度:500像素; border-top-color:#009900; >
< / table >
< / td >
< / tr >
< tr >
< td >
< asp:标签 ID = lblComment runat = server 文字 =' <% #Eval( 评论)% >' / >
< / td >
< / tr >
< tr >
< td >
< table style = border-removed1px dotted#df5015; border-removed1px solid#df5015;宽度:500像素; border-color:#00CC66#008000#00CC66#008000; >
< tr >
< ; td > < asp:ImageButton ID = imgbtnlike runat = server ImageUrl = 〜/ image / like.png 高度 = 20 Width = 20 OnClick = imgButton_Click CommandArgument =' <% #Eval( LIKES)%>' / >
< asp:Label < span class =code-attribute> ID = lblcount runat = server Text =' <% #Eval( LIKES)%>' > < asp:标签 ID = lbllike runat = 服务器 text = 喜欢 > < / td >
< td > 事件:< asp:标签 ID = lbleventID < span class =code-attribute> runat = server Font-Bold = true Tex t =' <% #Eval ( EvenConvID)%>' / > < / td >
< td > 创建日期:< asp:标签 ID = lblDate runat = 服务器 字体粗体 = true 文字 =' <% #Eval( DateTime)% >' / > < / td >

< / tr >
< / table >
< / td >
< / tr >
< tr >
< td colspan = 2 > < / td >
< / tr >
< / itemtemplate >
< footertemplate >
< / footertemplate > < span class =code-keyword>< / table >



代码视图:

<前lang =c#> 受保护 void imgButton_Click( object sender,EventArgs e)
{
ImageButton button =(sender as ImageButton);
string commandArgument = button.CommandArgument;
RepeaterItem item = button.NamingContainer as RepeaterItem;
int index = item.ItemIndex;
尝试
{
con.Open();
SqlCommand cmd = new SqlCommand( usp_likecount ,con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.Parameters.AddWithValue( @ EventID 1);
Label lbleventID = new Label();
cmd.Parameters.AddWithValue( @ EvenConvID,lbleventID.Text);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
RepDetails.DataSource = ds;
RepDetails.DataBind();
BindRepeaterData();

}
catch (例外情况)
{
lblerror.Text = ex.Message;
}

con.Close();
}



存储过程:



  USE  [******] 
GO
/ * *****对象:StoredProcedure [dbo]。[usp_likecount]脚本日期:02/27/2014 15:16:54 *** *** /
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo]。[usp_likecount]
@EventID varchar
@ EvenConvID int
AS
BEGIN
DECLARE @ like int
SELECT @ like =喜欢 FROM EventConv WHERE EventID = @ EventID AND EvenConvID = @ EvenConvID
更新 EventConv SET [喜欢] ] = @ like + 1 WHERE EvenConvID = @ EvenConvID
END

解决方案

我认为'RepDetails'没有正确获取数据源。不要参加'imgButton_Click'活动。我想你已经有'RepDetails_ItemCommand'事件了。



所以在那个事件中做所有操作并删除'OnClick =imgButton_Click '从图像按钮。



否则它将导致调用'RepDetails_ItemCommand'和'imgButton_Click'事件。


hi,
I want to display the count value of an image clicked (eg:Like in Facebook)in a label, so i wrote stored procedure to increment the value also my code under repeater,
Here my problem is im getting a error as "The IListSource does not contain any data sources" Plz Help me... Here i am attaching my code.


Source code:

  <asp:Repeater ID="RepDetails" runat="server" onitemcommand="RepDetails_ItemCommand">
<HeaderTemplate>
<table style=" border:1px solid #df5015; width:500px" cellpadding="0">
<tr style="background-color:#00CC66; color:White">
<td colspan="1" align="center">
Comments
</td>
</tr>
</HeaderTemplate>
<itemtemplate>
<tr style="background-color:#00CC66">
<td>
<table style="background-color:#EBEFF0;border-removed1px dotted #df5015; width:500px; border-top-color: #009900;">
</table>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblComment" runat="server" Text='<%#Eval("Comment") %>'/>
</td>
</tr>
<tr>
<td>
<table style="border-removed1px dotted #df5015;border-removed1px solid #df5015; width:500px; border-color: #00CC66 #008000 #00CC66 #008000;">
<tr>
<td><asp:ImageButton ID="imgbtnlike" runat="server" ImageUrl="~/image/like.png" Height="20" Width="20" OnClick = "imgButton_Click" CommandArgument='<%#Eval("LIKES") %>'/> 
<asp:Label ID="lblcount" runat="server" Text='<%#Eval("LIKES") %>'><asp:Label ID="lbllike" runat="server" text="Likes"></td>
<td>Event: <asp:Label ID="lbleventID" runat="server" Font-Bold="true"  Text='<%#Eval("EvenConvID") %>'/></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"> </td>
</tr>
</itemtemplate>
<footertemplate>
</footertemplate></table>


Code View:

protected void imgButton_Click(object sender, EventArgs e)
        {
            ImageButton button = (sender as ImageButton);
            string commandArgument = button.CommandArgument;
            RepeaterItem item = button.NamingContainer as RepeaterItem;
            int index = item.ItemIndex;
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("usp_likecount", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = con;
                cmd.Parameters.AddWithValue("@EventID", "1");
                Label lbleventID = new Label();
                cmd.Parameters.AddWithValue("@EvenConvID", lbleventID.Text);
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);
                RepDetails.DataSource = ds;
                RepDetails.DataBind();
                BindRepeaterData();

            }
            catch (Exception ex)
            {
                lblerror.Text = ex.Message;
            }

            con.Close();
        }


Stored Procedure:

USE [******]
GO
/****** Object:  StoredProcedure [dbo].[usp_likecount]    Script Date: 02/27/2014 15:16:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_likecount]
(@EventID varchar 
,@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

解决方案

I think 'RepDetails' is not getting data source properly. Don't take 'imgButton_Click' event.I think you already have 'RepDetails_ItemCommand' event.

So do all operations in that event & remove 'OnClick = "imgButton_Click"' from image button.

Other wise it will lead to call both 'RepDetails_ItemCommand' & 'imgButton_Click' events.


这篇关于显示标签中的点击次数!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆