开发者

NavigateUrl with NavigateUrlFormat populated from AppSettings (dynamically)

开发者 https://www.devze.com 2022-12-16 07:39 出处:网络
I h开发者_Python百科ave a gridview with a hyperlink inside an TemplateField. The NavigateUrlFormat will be populated from the Web.Config file, it has the following format:

I h开发者_Python百科ave a gridview with a hyperlink inside an TemplateField. The NavigateUrlFormat will be populated from the Web.Config file, it has the following format:

mysite.com/{0}

Where {0} will be populated from the gridview datasource, however, my current code doesn't work:

<asp:TemplateField HeaderText="WorkOrder #">
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" 
                        NavigateUrl='<%# Eval("WorkOrderKey", "<%$ AppSettings:DispatchLink %>") %&gt;' 
                        Text='<%# Eval("WorkOrderKey") %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>

The problem is right after "AppSettings:DispatchLink", it closes the tag when it see "%>". Is there a way around this problem?

Thank you, Kenny.


You cannot nest <%# and other tags. Use ConfigurationManager.AppSettings["DispatchLink"] (pls. lookup correkt Class/Property in MSDN) instead.

Or: If your are using that HyperLink Control more than once I would suggest that you create an own MYHyperLink derived from System.Web.UI.WebControls.HyperLink and set the Property NavigateUrlFormatString in your Constructor.

Something like this:

public class DispatchLink : System.Web.UI.WebControls.HyperLink
{
    public DispatchLink()
    {
        this. NavigateUrlFormatString  =  ConfigurationManager.AppSettings["DispatchLink"] 
    }
}
0

精彩评论

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

关注公众号