隐藏字段在asp.net中不起作用c# [英] hidden field is not working in asp.net c#

查看:53
本文介绍了隐藏字段在asp.net中不起作用c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

隐藏字段在asp.net中不起作用c#



hidden field is not working in asp.net c#

void counts()
    {

        foreach (RepeaterItem items in repeat.Items)
        {
            HiddenField comment_like = (HiddenField)items.FindControl("comment_id");
            Label user_counts = (Label)items.FindControl("user_counts");

            

            if (Request.QueryString["id"] != null)
            {
                int id;
                id = Convert.ToInt32(Request.QueryString["id"].ToString());
                con = new SqlConnection(str);
                con.Open();
                cmd = new SqlCommand("sp_command_count", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@eid", id);
                cmd.Parameters.AddWithValue("@comment_id", comment_like.Value);
                da = new SqlDataAdapter(cmd);
                dt = new DataTable();
                da.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    user_counts.Text = dr["total_count"].ToString() + "of" + dr["like_count"].ToString();

                    repeat.DataSource = dt;
                    repeat.DataBind();
                    review_panel.Visible = true;


                }
                else
                {
                    review_panel.Visible = false;
                }
                con.Close();
            }
        }
    }



asp.code






asp.code


<asp:Label ID="user_counts" runat="server" CssClass="counts">

                                     <asp:HiddenField ID="comment_like" runat="server" Value='<%#Eval("comment_id") %>' />





存储过程






stored procedure


ALTER PROCEDURE [dbo].[sp_command_count]

   (
    @eid int,
    @comment_id int
   )
AS
BEGIN
Declare  @sql int
    SET NOCOUNT ON;
      select @sql ='select *,(select c.comment_like from comments c where id=@eid and c.comment_id='+convert(varchar,@comment_id)+') as like_count,
          (select sum(comment_like+comment_dislike) from comments c where id=@eid and c.comment_id='+convert(varchar,@comment_id)+') as total_count from comments c
          where c.id=@eid and c.comment_id='+convert(varchar,@comment_id)+''
      END

推荐答案

问题在这里

Problem is here
foreach (RepeaterItem items in repeat.Items)
        {
            HiddenField comment_like = (HiddenField)items.FindControl("comment_id");



您的隐藏字段id是 comment_like ,但您正在尝试找到ID comment_id 的隐藏字段,而不是那里。

将此更改为


Your hidden field id is comment_like but you are trying to find hidden field with id comment_id which not there.
Change this to

foreach (RepeaterItem items in repeat.Items)
        {
            HiddenField comment_like = (HiddenField)items.FindControl("comment_like");





希望,这有助于:)



Hope, this helps :)


这篇关于隐藏字段在asp.net中不起作用c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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