开发者

How to access application setting through markup using expression?

开发者 https://www.devze.com 2022-12-23 05:07 出处:网络
In a repeater control I\'ve Eval binding as: <%#Eval(\"PubDate\", \"{0:dd-MMM-yyyy}\")%> But date time format needs to be configurable from the web.config.

In a repeater control I've Eval binding as:

<%#Eval("PubDate", "{0:dd-MMM-yyyy}")%>

But date time format needs to be configurable from the web.config. I want to access datetime format from web.config in markup like:

<%#Eval("PubDate", "{0:<%$ AppSettings: DateTimeFormat %>}")%>

But is is not working... Any suggesio开发者_开发知识库ns?


You can create a property on your page in code behind (e.g. AppDateTimeFormat) which accesses DateTimeFormat from the AppSettings and use it like this:

    <%#Eval("PubDate", AppDateTimeFormat)%>


Try this one:

<%# Eval("PubDate", "{0:" + ConfigurationManager.AppSettings["DateTimeFormat"] + "}")%>

Edit: I'd recommend placing the parenthesis inside the String. Then you'd be able to use

<%# Eval("PubDate", ConfigurationManager.AppSettings["DateTimeFormat"])%>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号