How to Eval a value in my config file
I have the following case:
I store a specific path in my web.config file like this:
<add key="pdfPath" value="domainName/aa/pdf/"/>
and I want to eval
this value in my hyperlink in my DetailsView
:
<asp:TemplateField HeaderText="pdf file">
<asp:HyperLink ID="hl_link" runat="server" N开发者_开发知识库avigateUrl='<%#Eval("thevaluefromConfigfile")%>'><%#Eval("filename") %></asp:HyperLink>
</asp:TemplateField>
How do I read the value from my configuration file?
I want this link to open in a new window. Is the hyperlink the best choice?
Check this code
Replace
<asp:HyperLink ID="hl_link" runat="server" NavigateUrl='<%#Eval("thevaluefromConfigfile")%>'><%#Eval("filename") %></asp:HyperLink>
With
<asp:HyperLink ID="hl_link" runat="server" NavigateUrl='<%$ AppSettings:thevaluefromConfigfile %>'><%$ AppSettings:filename %></asp:HyperLink>
Is it possible for you to use anchor tag? If yes then use that one it will navigate you on separate new window, while you can also use window.open() function in navigateURL to open new window. For further information check this link and also this link.
Use a A tag instead
<a id="hl_link" target="_blank"
href='<%#ConfigurationSettings.AppSettings["pdfPath"]%>'><%#Eval("filename") %></a>
how to read the key:
ConfigurationSettings.AppSettings["pdfPath"];
Use <%$ AppSettings:pdfPath %>
probably you should replace:
<%#Eval("thevaluefromConfigfile")%>
with something like this:
<%# ConfigurationManager.AppSettings["pdfPath"] %>
精彩评论