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

  • SEARCH
  • Home
  • 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

Related Questions

I currently have a DetailsView (used to be a Formview, but that is a
I currently have a simple app that includes user authentication through devise and a
I currently have a project converting asp classic codes to C#, then i came
I currently have Core Data successfully returning all of the results for a specific
Currently have this: foreach (var series in Chart1.Series) { series.Enabled = false; } I
I currently have git and virtualenv set up in a way which exactly suits
I currently have a main stored procedure calling many stored procedures: Main --| --|
I currently have a C# form, although I would like to find out how
I currently have a shared folder with 2 other (not very technical) people where
I am new to Django and I am trying to build a data hierarchy

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.