Asp.Net用户控件中的IF条件 [英] IF condition in Asp.Net User Control

查看:92
本文介绍了Asp.Net用户控件中的IF条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个用户控件,其中包含asp.net转发器的代码。我在其他页面中使用此控件。在后面的用户控制代码中,我使用LING to SQL从数据库中获取数据。在转发器中,我需要显示特定键值的链接。所以,我需要在.ascx页面中添加一个If语句。这是我正在使用的IF条件代码,



 <%  if %>  <%#( string )DataBinder.Eval(Container.DataItem,  key%>  =50)
<% {%>
< a id = A1 href = http://www.google.com <跨度class =code-attribute> target = _ blank > 测试链接< / a >
<%} else {< span class =code-pagedirective>%>
< a id = A2 > < / a >
<%} %>





但是在此声明中显示错误。



我已经护目镜并试过这个:



 <%  if ((%>  <%# ( string )DataBinder.Eval(Container.DataItem,  key%>  <%)。equals(  50)){
< a id = testmore href = http:// www.google.com target = _ blank runat = server>测试链接< / a >
}%>





和这种方式:

 <   a     id   =  testmore    href   =  http://www.google.com    target   =  _ blank      runat   =  server    

可见 = < span class =code-pagedirective><% if %> (< span class =code-pagedirective><%#( string )DataBinder.Eval(Container.DataItem, key%> <% = 50)? true false %> > 测试链接







但是,这种格式都没有正常工作。



任何人都可以给我正确的格式来写这个声明。如果你还需要,请告诉我信息。



先谢谢。



Scorpion

解决方案

将字符串key值保存在服务器端事件的公开声明的变量中,然后在您的aspx代码中访问它。



  public   string  myKey =  string .Empty; 





然后在你的aspx代码中



<![CDATA [<% if (myKey ==   50
{
% > ]] >
< a id = A1 href = http://www.google.com target = _ blank>测试链接< / a >
<%}
其他
{
%>
< a id = A2 > < span class =code-keyword>< / a >
<%} %>


Hi,

I have a user control which has code for asp.net repeater. I am using this control in other page. In the user control code behind I am using LING to SQL to get the data from database. In the repeater, I need to display a link for a specific key value. So, I need added an If statement in the .ascx page. Here is the IF condition code I am using,

<% if (%> <%#(string)DataBinder.Eval(Container.DataItem, "key")%>= "50")
<%{%>
<a id="A1" href="http://www.google.com" target="_blank">test link</a>
<%}else{%>
<a id="A2"></a>
<%}%>



But it is showing error in this statement.

I have goggled and also tried this:

<% if ((%> <%#(string)DataBinder.Eval(Container.DataItem, "key")%> <%).equals("50")) {
<a id="testmore" href="http://www.google.com" target="_blank" runat="server" >test link</a>
} %>



and this way:

<a id="testmore" href="http://www.google.com" target="_blank"  runat="server" 

visible="<%if%>(<%#(string)DataBinder.Eval(Container.DataItem, "key")%><%= "50") ? true : false%>">test link 




But, none of this format are working correctly.

Can any one give me the correct format to write this statement. Please let me know if you need any more information.

Thanks in Advance.

Scorpion

解决方案

Save your string "key" value in a publicly declared variable in your server side event, then access it in your aspx code.

public string myKey = string.Empty;



then in your aspx code

<![CDATA[<% if (myKey == "50")
   {
%>]]>
<a id="A1" href="http://www.google.com" target="_blank">test link</a>
    <%}
   else 
   {
%>
<a id="A2"></a>
    <%}%>


这篇关于Asp.Net用户控件中的IF条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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