在ASP.NET中使用函数设置imageURL在ASP.NET中使用函数我以前在repeater中做过这个并且它成功了。但是,我无法在普通网络表单中找到以下内容。图像显示为断开的链接,我在代码隐藏中的断点不会被触发。(在aspx文件中)(代码隐藏)这是我尝试的第二种方法,在另一种方法中,我尝试将图像名称作为字符串传递,并以这种方式返回整个链接。仍然没有运气!有任何想法吗?谢谢![编辑]感谢大家的帮助。最后,在一个方便的提示之后,我找到了一个递归代码片段,其功能如下:privatevoidUpdateImages(ControlParent){foreach(ControlcinParent.Controls){if(i!=null){i.ImageUrl="~/App_Variants/LBSX/images/"+i.ImageUrl;}if(c.HasControls()){UpdateImages(c);}}}protectedvoidPage_Load(objectsender,EventArgse){UpdateImages(Page);...希望它能帮助别人。干杯首先,就像Zachary提到的那样,您正在使用代码块进行数据绑定。其次,正如您已经尝试过的那样,使用内联表达式()在您的情况下不起作用,因为您不能在服务器标记的任何属性上使用内联表达式。你可以做的是使用HTML语法定义一个图像按钮,省略runat="server"标签,并使用内联表达式来获取图像的URL:btnRunReport.png"name="image"/>内联表达式是什么确实是,它调用Response.Write()并将值介于两者之间作为参数,例如Response.Write(this.MyVar)。你的语法用于数据绑定。如果你只是想使用内联c#,你应该使用...我给你另一个解决方案。使用ExpressionBuilder:创建一个从ExpressionBuilder开始的类并覆盖函数GetCodeExpressionnamespaceyour.namespace{publicclassCustomBuilder:ExpressionBuilder{publicoverrideCodeExpressionGetCodeExpression(BoundPropertyEntryentry,objectparsedData,ExpressionBuilderContextcontext){Typetype1=entry.DeclaringType;PropertyDescriptordescriptor1=TypeDescriptor.GetProperties(type1)[entry.PropertyInfo.Name];CodeExpression[]expressionArray1=newCodeExpression[1];expressionArray1[0]=newCodePrimitiveExpression(entry.Expression.Trim());Stringtemp=entry.Expression;返回新的CodeCastExpression(descriptor1.PropertyType,newCodeMethodInvokeExpression(newCodeTypeReferenceExpression(base.GetType()),"GenerateLink",expressionArray1));}publicstaticStringGenerateLink(Stringlink){returnConfigurationManager.AppSettings["MediaPath"]+link+"?ver="+ConfigurationManager.AppSettings["MediaCode"];}}}expressionArray1是GenerateLink函数的传输你可以根据函数的输入参数个数来改变数组的大小2.在webconfig中注册表达式3.在视图中你可以使用新的表达式:'/>4.Enjoy!!!以上就是C#学习教程:使用ASP.NET中的函数设置imageURL分享的所有内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: