在转发器控制中为多个(如果不是)

时间:2018-11-22 14:48:57

标签: c# eval repeater

<asp:Repeater runat="server" ID="listcount" OnItemCommand="change">
<ItemTemplate>
 <td><asp:ImageButton ID="btnlike" runat="server" src="images/sheart1.png" CommandName="like" CommandArgument='<%#Eval("commentid")+","+ Eval("likeunlike")%>'  Visible='<%# Convert.ToInt32(Eval("likeunlike")) == 1 ? true :  false%>' />
 <asp:ImageButton ID="btnunlike" runat="server" src="images/heart1.png" CommandName="unlike" CommandArgument='<%#Eval("commentid")+","+ Eval("likeunlike")%>'  Visible='<%# Convert.ToInt32(Eval("likeunlike")) == 0 ? true : false%>'  />
</ItemTemplate>
</Repeater>

我的代码后面:

private void load()
    {
        string id = Request.QueryString["id"];
        string strConn = Convert.ToString(
         ConfigurationManager.ConnectionStrings
         ["Fundverse"]);

        using (SqlConnection con = new SqlConnection(strConn))
        {
            using (SqlCommand cmd = new SqlCommand("select 
tbllike.likeunlike, tbllike.commentid from tbllike inner join tblcomments on 
tbllike.commentid = tblcomments.id where tblcomments.username = 
'kelvinhappy@hotmail.com' and tblcomments.campaignid = " + 18, con))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    listcount.DataSource = dt;
                    listcount.DataBind();
                }

            }
         }
    }

我尝试解决可见部分。有人可以通过if else语句帮助我吗,因为cuz select语句将返回行0。我不确定要更改为     可见='<%#Convert.ToInt32(Eval(“ likeunlike”))== 0 || Eval(“ likeunlike)=     DB.Value吗? true:假%>' 我想在这里实现的是,当没有行返回可见时,ID =“ btnunlike”仍然适用。

0 个答案:

没有答案