我有一个页面可以按名称搜索产品。
在许多页面中,我使用产品代码。如果用户不知道产品代码,我让他去这个页面,按名称搜索,然后选择一个结果,回到他来自的页面。

在按名称搜索的结果中,我设置了一个 HyperLinkField,它将重定向到某个页面,并带有产品代码的参数。

我的代码是这样的:

 <asp:GridView ID="GridView1" Runat="server"
  DataSource='<%# GetData(pName.Text) %>' AutoGenerateColumns="False">
    <Columns>
        <asp:BoundField DataField="Name">
            <ItemStyle HorizontalAlign="Center"
              VerticalAlign="Middle"></ItemStyle>
        </asp:BoundField>
        <asp:BoundField  DataField="Code"></asp:BoundField>
        <asp:ImageField ControlStyle-Width="150px"  ControlStyle-Height="150px" DataImageUrlField="PictureURL" ></asp:ImageField>
        <ASP:HYPERLINKFIELD text=">>" datanavigateurlfields="Code"  datanavigateurlformatstring="priceUpdater.aspx?ProductCode={0}"></ASP:HYPERLINKFIELD>
    </Columns>
</asp:GridView>

其中 GetData 是一个函数,它返回一个 Product 类型的对象,其中包含字段、名称、代码、图像等。

如您所见,HYPERLINKFIELD 中的此链接将重定向到名为 priceUpdater 的页面,其中包含产品代码的参数。

我希望这个页面是动态的。
我试图像这样向搜索页面添加一个参数
 <%string pageRequested = Page.Request.QueryString["SearchScreen"];%>

现在我试图像这样使用超链接:
<ASP:HYPERLINKFIELD text=">>" datanavigateurlfields="Code"  datanavigateurlformatstring="<%=pageRequested%>.aspx?ProductCode={0}"></ASP:HYPERLINKFIELD>

但是链接所指向的页面与 writen 一样纯文本(http://mysite.com/%3C%=pageRequested% >.aspx?ProductCode=2450)

我怎样才能使这项工作?

谢谢!

最佳答案

试试看:

<asp:TemplateField>
<ItemTemplate>
    <ASP:HYPERLINK text=">>" NavigateUrl='<%# String.Format("~/{0}.aspx?ProductCode={1}",Page.Request.QueryString["SearchScreen"],Eval("Code")) %>'></ASP:HYPERLINK>
</ItemTemplate>
</asp:TemplateField>

关于c# - asp :GridView HYPERLINKFIELD - asp code inside datanavigateurlformatstring,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17649296/

10-10 07:47