0

I need to have a hyperlink field in 1 of the data items inside of the datalist. How should I go about to do this?

<asp:HyperLinkField DataNavigateUrlFields="ProductId" 
    DataNavigateUrlFormatString="ProductDetails.aspx?ProductId={0}" 
    DataTextField="ProductName" HeaderText="Product Name" />

This is the field I would like to put inside one of the datalist item.

Please advise. Thanks.

My data list looks like:

<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" DataSourceID="AccessDataSource1"
    CellPadding="4" ForeColor="#333333" DataKeyField="ProductId" RepeatColumns="3">
    <AlternatingItemStyle BackColor="White" />
    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <ItemStyle BackColor="#FFFBD6" ForeColor="#333333" />
    <ItemTemplate>
        ProductId:
        <asp:Label ID="ProductIdLabel" runat="server" Text='<%# Eval("ProductId") %>' />
        <br />
        ProductName:
        <asp:HyperLinkField DataNavigateUrlFields="ProductId" DataNavigateUrlFormatString="ProductDetails.aspx?ProductId={0}"
            DataTextField="ProductName" HeaderText="Product Name" />
        <br />
        SalesItem:
        <asp:Label ID="SalesItemLabel" runat="server" Text='<%# Eval("SalesItem") %>' />
        <br />
        ProductCategory:
        <asp:Label ID="ProductCategoryLabel" runat="server" Text='<%# Eval("ProductCategory") %>' />
        <br />
        NormalPrice:
        <asp:Label ID="NormalPriceLabel" runat="server" Text='<%# Eval("NormalPrice") %>' />
        <br />
        PromotionPrice:
        <asp:Label ID="PromotionPriceLabel" runat="server" Text='<%# Eval("PromotionPrice") %>' />
        <br />
        QuantityOnHand:
        <asp:Label ID="QuantityOnHandLabel" runat="server" Text='<%# Eval("QuantityOnHand") %>' />
        <br />
        <br />
    </ItemTemplate>
    <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
</asp:DataList>

As you can see, i tried to put the hyperlink into the "Product Name" but it doesn't work.

4

1 回答 1

0

Try this:

<asp:HyperLink ID="ProductNameLink" 
    runat="server"
    NavigateUrl='<%# "ProductDetails.aspx?ProductId=" + Eval("ProductId").ToString() %>'
    Text='<%# Eval("ProductName") %>'/>
于 2013-07-04T12:21:39.117 回答