Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 55585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:24:02+00:00 2026-05-10T17:24:02+00:00

I currently have a DetailsView in ASP.NET that gets data from the database based

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:24:02+00:00Added an answer on May 10, 2026 at 5:24 pm

    Use the CommandName and the CommandArgument parameters of the Button class. Specifying a CommandName will expose the ItemCommand event. From there you can check for the CommandName, easily grab the CommandArgument (the ID of your row or item) then push whatever data your need into your cookie that way.

    More formally, you’re looking to have your button like this:

    <asp:Button ID='btnAddArt' CommandName='AddCard' CommandArgument='[ArtID]' runat='server' Text='Add To Cart' /> 

    Then your code behind can function like this:

    Private Sub ProcessDetailsViewCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles DetailsView1.ItemCommand  ' Using Case statement makes it easy to add more custom commands later on. Select Case e.CommandName     Case 'AddCard'       Dim CartArtID As New HttpCookie('CartArtID')       CartArtID.Value = Integer.Parse(e.CommandArgument.ToString)       CartArtID.Expires = Date.Today.AddDays(0.5)       Response.Cookies.Add(CartArtID)       Response.Redirect('Purchase.aspx')     End Select End Sub 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 152k
  • Answers 152k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I follow Jon Skeet and others on his blogroll Ian… May 12, 2026 at 10:05 am
  • Editorial Team
    Editorial Team added an answer Easiest way to find out would be to start writing… May 12, 2026 at 10:05 am
  • Editorial Team
    Editorial Team added an answer There are several use cases where its useful to allow… May 12, 2026 at 10:05 am

Related Questions

I have a TemplateField in a DetailsView and its input should be one of
Currently I have a DetailsView attached to a GridView. When you select an item
I have a basic test web form with a DataList and a DetailsView and
I'm working on an application that will have attachments, and I would like to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.