如何在ASP.NET C#中嵌入复杂的评估表达式? [英] How to embed complex evaluation expressions in ASP.NET C# ?

查看:74
本文介绍了如何在ASP.NET C#中嵌入复杂的评估表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我最近开始将代码从VB转换为C#并偶然发现了什么。在aspx页面上的VB.NET上,我可以轻松地对这样的会话和eval值进行评估...



Hi all

I recently started converting code from VB to C# and stumbled upon something. On VB.NET on the aspx page I can easily do an evaluation of session and eval values like this ...

<asp:ImageButton CssClass="images" ID="btnDelete" runat="server" ToolTip="Remove" Visible='<%# Session("Role") = 3 And Eval("IsClosed") = False And Eval("Deleted") = False%>'/>





我可以使用复杂的嵌入式表达式来控制使用VB的可见属性,但我似乎可以在C#上找到一种方法。



是有一种方法可以轻松地在C#



I can use a complex embedded expression to control the visible property using VB, but I can seem to find a way to do it on C#.

Is there a way of easily doing this on C#

推荐答案

nfiguer写道:
nfiguer wrote:



嗨谢尔盖



我想要实现的目标非常简单。在这种情况下(见上面的代码)我试图设置按钮可见属性考虑到一些条件。在VB.NET中,我只是将此代码嵌入到可见属性的aspx代码中。在C#中无法做到这一点,因为看起来VB最终会比C#


Hi Sergey

What I am trying to achieve is quite simple. In this case (see code above) I am trying to set the button visible property taking into account a few conditions. In VB.NET I simply embed this code in the visible property aspx code. Not able to do that in C#, which is a bummer since it appears that VB ends up being more powerful at this than C#

更强大,我不记得VB(不管它是什么)比C#更强大(相反肯定)发生);这只是你的品味问题。



但语言只是.NET语言,并且在功能上保持彼此接近。它们足够接近,可以自动,干净地翻译成另一个。请看我过去的答案:

代码解释,C#到VB.NET [ ^ ],

需要将vb代码转换为c# [ ^ ]。



-SA

I don't remember VB (whatever it is) being more powerful than C# (the opposite certainly happen); this is rather a matter of your taste.

But the languages are just the .NET languages and are kept close to each other functionally. They are close enough to be automatically and cleanly translated one into another. Please see my past answers:
Code Interpretation, C# to VB.NET[^],
Need to convert vb code to c#[^].

—SA


C#完全准确相同的功能 - 你只需要将表达式转换为C#,并插入所需的类型转换:

C# has exactly the same functionality available - you just need to convert the expression to C#, and insert the required type-casts:
<asp:ImageButton CssClass="images" ID="btnDelete" runat="server" ToolTip="Remove" Visible='<%# (int)Session["Role"] == 3 && (bool)Eval("IsClosed") == false && (bool)Eval("Deleted") == false %>'/>



注意:此语法仅适用于数据绑定控件。无论代码的语言如何,都适用相同的限制。


NB: This syntax only works within a data-bound control. The same limitation applies regardless of the code's language.


尝试使用C#Web服务调用服务器上的某些C#代码以获得足够的计算能力。

这是一个链接到 C#Web服务的指南。



为什么不使用javascript?
Try a C# Webservice to invoke some C# code on a server to have enough computation power.
Here is a link to a guide for C# Web Service.

Why dont you use javascript?


这篇关于如何在ASP.NET C#中嵌入复杂的评估表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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