Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. GridView Edit..

GridView Edit..

Scheduled Pinned Locked Moved ASP.NET
databasequestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dio22
    wrote on last edited by
    #1

    I need several buttons on each GridView row that redirect to pages performing custom operations. How do I get the DataKey of the row the button was clicked on? So that I can send the database ID of the row I want to perform operations on to another page. I can't use GridView.SelectedDataKey.Value because i'm not always going to be clicking the select button. Nor can I use the index, because that is not the ID for the data in the database.

    D 1 Reply Last reply
    0
    • D Dio22

      I need several buttons on each GridView row that redirect to pages performing custom operations. How do I get the DataKey of the row the button was clicked on? So that I can send the database ID of the row I want to perform operations on to another page. I can't use GridView.SelectedDataKey.Value because i'm not always going to be clicking the select button. Nor can I use the index, because that is not the ID for the data in the database.

      D Offline
      D Offline
      Dio22
      wrote on last edited by
      #2

      Nevermind. :) This is how I did it. If someone knows a better way, lemme know. I created a button commandField with command "EditRow" and hooked up the RowCommand event.

      protected void MainGrid_RowCommand(object sender, GridViewCommandEventArgs e)
      {
         if (e.CommandName == "EditRow")
         {
          DataKey mykey = MainGrid.DataKeys[Convert.ToInt32(e.CommandArgument)];
          String mystring = Convert.ToString(mykey.Value);
          Page.Response.Redirect("Insert.aspx?key=" + mystring);
          }
      }
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups