我需要在数据列表中的一个数据项中有一个超链接字段。我该怎么做?
<asp:HyperLinkField DataNavigateUrlFields="ProductId"
DataNavigateUrlFormatString="ProductDetails.aspx?ProductId={0}"
DataTextField="ProductName" HeaderText="Product Name" />
这是我想放在其中一个数据列表项目中的字段。
请告知。谢谢
我的数据列表看起来像:
<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>
正如你所看到的,我试图将超链接放入"产品名称"中,但它不起作用。
试试这个:
<asp:HyperLink ID="ProductNameLink"
runat="server"
NavigateUrl='<%# "ProductDetails.aspx?ProductId=" + Eval("ProductId").ToString() %>'
Text='<%# Eval("ProductName") %>'/>