I currently have a DetailsView in ASP.NET that gets data from the database based on an ID passed through a QueryString. What I've been trying to do now is to then use that same ID in a new cookie that is created when a user clicks either a ButtonField or a HyperLinkField.
What I have in the .aspx is this:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ArtID"
DataSourceID="AccessDataSource1" Height="50px" Width="125px">
<Fields>
<asp:ImageField DataAlternateTextField="Title" DataImageUrlField="FileLocation">
</asp:ImageField>
<asp:BoundField DataField="ArtID" HeaderText="ArtID" InsertVisible="False" ReadOnly="True"
SortExpression="ArtID" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="ArtDate" HeaderText="ArtDate" SortExpression="ArtDate" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="FileLocation" HeaderText="FileLocation" SortExpression="FileLocation" />
<asp:BoundField DataField="Medium" HeaderText="Medium" SortExpression="Medium" />
<asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
<asp:BoundField DataField="PageViews" HeaderText="PageViews" SortExpression="PageViews" />
<asp:HyperLinkField DataNavigateUrlFields="ArtID" DataNavigateUrlFormatString="Purchase.aspx?ArtID={0}"
NavigateUrl="Purchase.aspx" Text="Add To Cart" />
<asp:ButtonField ButtonType="Button" DataTextField="ArtID" Text="Add to Cart" CommandName="btnAddToCart_Click" />
</Fields>
</asp:DetailsView>
When using a reguler asp.net button such as:
<asp:Button ID="btnAddArt" runat="server" Text="Add To Cart" />
I would have something like this in the VB:
Protected Sub btnAddArt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddArt.Click
Dim CartArtID As New HttpCookie("CartArtID")
CartArtID.Value = ArtID.DataField
CartArtID.Expires = Date.Today.AddDays(0.5)
Response.Cookies.Add(CartArtID)
Response.Redirect("Purchase.aspx")
End Sub
However, I can't figure out how I go about applying this to the ButtonField instead since the ButtonField does not allow me to give it an ID.
The ID that I need to add to the cookie is the ArtID in the first BoundField.
Any idea's/advice on how I would go about doing this are greatly appreciated!
Alternatively, if I could do it with the HyperLinkField or with the regular button, that would be just as good, but I'm having trouble using a regular button to access the ID within the DetailsView.
Thanks