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. DataKey from a gridview

DataKey from a gridview

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-netsalesworkspace
7 Posts 2 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.
  • M Offline
    M Offline
    Malayil alex
    wrote on last edited by
    #1

    Hi there, I am in a problem..like i have one gridview and the DataKeyNames is say "ID" i have one imagebutton field for changin the status of a customer in that image button i setup one commandargument field say "StatusValue"..and the CommandName is Status... when i click status button ie, in the "GridView1_RowCommand" event i need both the values ie ID and StatusValue corresponding to that row.... Can anybody give me a help to solve this... i am using asp.net 2.0 and c#

    T 1 Reply Last reply
    0
    • M Malayil alex

      Hi there, I am in a problem..like i have one gridview and the DataKeyNames is say "ID" i have one imagebutton field for changin the status of a customer in that image button i setup one commandargument field say "StatusValue"..and the CommandName is Status... when i click status button ie, in the "GridView1_RowCommand" event i need both the values ie ID and StatusValue corresponding to that row.... Can anybody give me a help to solve this... i am using asp.net 2.0 and c#

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      Use the gridviews rowdatabound event.

      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {

          // on each row which is DataRow populate dropdown lists
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
             
             
      
              Button Button1 = (Button)e.Row.FindControl("Button1");
      
           
              //could be dbdatarecords (for datareader) or other object You may have to modify this
              DataRowView drv = (DataRowView)e.Row.DataItem;
      
             // Add values to button
            Button1.attributes.add("id", dvr\["id"\].tostring());
            }
        }
      

      I didn't get any requirements for the signature

      M 1 Reply Last reply
      0
      • T ToddHileHoffer

        Use the gridviews rowdatabound event.

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            // on each row which is DataRow populate dropdown lists
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
               
               
        
                Button Button1 = (Button)e.Row.FindControl("Button1");
        
             
                //could be dbdatarecords (for datareader) or other object You may have to modify this
                DataRowView drv = (DataRowView)e.Row.DataItem;
        
               // Add values to button
              Button1.attributes.add("id", dvr\["id"\].tostring());
              }
          }
        

        I didn't get any requirements for the signature

        M Offline
        M Offline
        Malayil alex
        wrote on last edited by
        #3

        hi thanks for your response..but i coudn't able to come up with a result...i set the attributes with id value but how can i retrieve those values...now i have command arguemnet in image button and the id value is in imagebutton's ID value..so how can i retrieve those values in row command u have any idea. regards alex.

        T 1 Reply Last reply
        0
        • M Malayil alex

          hi thanks for your response..but i coudn't able to come up with a result...i set the attributes with id value but how can i retrieve those values...now i have command arguemnet in image button and the id value is in imagebutton's ID value..so how can i retrieve those values in row command u have any idea. regards alex.

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          Button button1 = (button)sender; button1.attribute["ID"].value ?

          I didn't get any requirements for the signature

          M 1 Reply Last reply
          0
          • T ToddHileHoffer

            Button button1 = (button)sender; button1.attribute["ID"].value ?

            I didn't get any requirements for the signature

            M Offline
            M Offline
            Malayil alex
            wrote on last edited by
            #5

            Hi, No that's not possible..because gridview is the sender....because image button is inside the gridview..i tried but it makes error.... regards alex

            T 1 Reply Last reply
            0
            • M Malayil alex

              Hi, No that's not possible..because gridview is the sender....because image button is inside the gridview..i tried but it makes error.... regards alex

              T Offline
              T Offline
              ToddHileHoffer
              wrote on last edited by
              #6

              Sorry, I guess I usually used an item template column. You should still be able to determine the gridviewrow and use its findcontrol method. If that doesn't work you could pass both values as the command argument and use string.split. I'm sure you can figure it out.

              I didn't get any requirements for the signature

              M 1 Reply Last reply
              0
              • T ToddHileHoffer

                Sorry, I guess I usually used an item template column. You should still be able to determine the gridviewrow and use its findcontrol method. If that doesn't work you could pass both values as the command argument and use string.split. I'm sure you can figure it out.

                I didn't get any requirements for the signature

                M Offline
                M Offline
                Malayil alex
                wrote on last edited by
                #7

                Hi, Thanks man finally it works..i used both values in the command arguement and split it out... thanks once again. regards alex.

                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