看到此代码中的错误 [英] See the error in this code

查看:60
本文介绍了看到此代码中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

Hi All,

<%if (Convert.ToInt32(Eval("article_comment_counter")) > 0)
                                {%><a href="articles_comments.aspx?article_id=<%# Eval("article_id")%>"><%# Eval("article_comment_counter")%>comments</a> | <%}
                                else
                                {%><i>0 comments</i>


如果我使用此代码,则显示如下错误:

诸如Eval(),XPath()和Bind()之类的数据绑定方法只能在数据绑定控件的上下文中使用.

请帮帮我.

在此先感谢.

我可以在后面的代码中执行此操作吗?
如果可以,怎么办?
我想在源代码页面中进行操作,如果有的话请帮助我.


If I used this code then it shown error like this:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Please help me.

Thanks in Advance.

Can I do this in code behind?
If so, how?
I want to do in source page, if any one do then please help me.

推荐答案

尝试在<%"和"if ,如果此代码中包含text值.

实际上,您可以将这些代码作为函数移至.cs,然后在运行程序时会发现错误.
Try to add a "#" between "<%" and "if ",if this code in a value of text .

Actually you can move these codes to .cs as a function, then you will find bug when you run the program.


对于背后的代码:

方法1:从源代码中删除服务器代码,并将锚标签保留在具有runat ="server"属性的面板或div中.因此,您可以在检查适当的条件后从代码后面设置visible属性.

方法2:而不是使用锚标记.用超链接控件代替它.它将使用服务器端对其进行控制的方式呈现相同的定位标记.因此,您可以在检查适当的条件后使用其visible属性将隐藏的代码显示在代码后面.

并且如果只需要使用Source而不是将其替换为以下内容
For Code Behind:

Way 1 : Remove the server code from source and keep the anchor tag in a panel or div with runat="server" attribute. So you can set the visible property from code behind after checking appropriate condition.

Way 2 : Rather than using anchor tag. Substitute it with hyperlink control. It will render the same anchor tag with the server side control over it. So you can hide show it from code behind using its visible property after checking appropriate condition.

And if it is necessary to do with Source only than replace it with following
<%#if (Convert.ToInt32(Eval("article_comment_counter")) > 0)
                                {%><a href="articles_comments.aspx?article_id=<%# Eval("article_id")%>"><%# Eval("article_comment_counter")%>comments</a> | <%}
                                else
                                {%><i>0 comments</i>



希望对您有所帮助:)



Hope it helps :)


嗨 希望这段代码对您有所帮助
Hi I hope this code help you little bit
<br />
<pre lang="xml"><span id="Span1" style=''<%#(Convert.ToInt32(Eval("UserRole"))==1)? "display:none;": "display:inline;" %>''><br />
                               <asp:LinkButton CssClass="gray-btn" ID="LinkDelete" runat="server" CommandName="select"<br />
                                   OnClientClick="Confrim(); if(confrim){return true;}else{return false;}"><img src="<%= Constants.RealUrl %>images/delete-icon.gif" alt="<%= delete %>" /> <%= delete%></asp:LinkButton><br />
                           </span></pre><br />
<br />


这篇关于看到此代码中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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