[英]In C#, how can I reference a specific product record based on a button that's clicked in a gridview row
I have a page that displays a gridview of products. 我有一个页面,显示产品的gridview。 Inside this table is a column with a hyperlink called "Details." 该表内部是一列,其中包含一个称为“详细信息”的超链接。 I want to make it so that if the user clicks the details cell for that specific product, a new page will open that gives more information on that product. 我要这样做,以便如果用户单击该特定产品的详细信息单元,将打开一个新页面,其中提供了有关该产品的更多信息。 I'm not sure how I would determine which Product
record the details link is in and how I would carry that over to the next page. 我不确定如何确定详细信息链接位于哪个Product
记录中,以及如何将其带到下一页。
You use a HyperlinkField which uses the ID of the product in the querystring. 您使用HyperlinkField,它在查询字符串中使用产品的ID。
Here's a sample: 这是一个示例:
<asp:GridView runat="server" ID="gridViewProducts">
<Columns>
<asp:HyperLinkField HeaderText="ProductId" DataNavigateUrlFormatString="ProductDetail.aspx?action=edit&id={0}" DataNavigateUrlFields="ProductId" DataTextField="ProductId" />
<asp:BoundField HeaderText="Product Name" DataField="ProductName" />
</Columns>
</asp:GridView>
When you bind, the productID automatically goes into the querystring 绑定时,productID自动进入查询字符串
As far as "linking" your product records, programmers do this using unique identifiers. 至于“链接”您的产品记录,程序员使用唯一的标识符来完成。 In most circumstances, you'll use an integer. 在大多数情况下,您将使用整数。
Historically, people have used the query string to pass database IDs from one page to another. 历史上,人们使用查询字符串将数据库ID从一页传递到另一页。 In ASP.NET, you can do this as well. 在ASP.NET中,您也可以这样做。 Alternatively, you could store the product ID in the Session
and then load that ID from the Session
in your new page. 或者,您可以在Session
存储产品ID,然后在新页面中从Session
中加载该ID。
You can take the productId by index property of the gridview. 您可以通过gridview的index属性获取productId。 Using that productId, you can navigate to the details of a particular product. 使用该productId,您可以导航到特定产品的详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.