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. Getting column data from GridView on page using MasterPage

Getting column data from GridView on page using MasterPage

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netquestion
17 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 marconi Flangepants

    Grapes-R-Fun wrote:

    Do this: create a control at runtime to match your Gridview's templated control Label lbl = GridView1.FindControl(Label1); _yourVariable = lbl.text; Also I would imagine you gotta do this for the Label1 control appearing on EACH row... do you know how to do that?

    Nila, dont worry i didnt take the comment as bad. Let me re-iterate what im trying to do, just to clarify we are thinking along the same lines. Ok, i have a gridview displaying data, when i click the select button on a given row i need to get the value of the data (unique_id) displayed in the first column. This column is also the DataKey for the gridview. So how can i get this info? Ive tried all sorts but to no avail. What would you suggest and how would you implement it? Sorry if this seems like im asking you to tell me how to do it all, but ive tried that many ways that should work and dont, that i really would appreciate it if you could explain in as much detail as possible. I dont know if this makes any difference but i am using MasterPage for the template of the page. I read somewhere that you have to drill right down to the control if using MasterPages. Is this true, and does it apply in this instance? If what you said above is still true Label lbl = GridView1.FindControl(Label1); _yourVariable = lbl.text; Then how would you implement this? At present ive tried both SelectedIndexChanged / SelectedIndexChanging, but without success. I get the error that the Object Referenced does not exist. This happenes no matter if i try indexing the column or the Label1 control used to display the info in the required column. So again, id be really greatful if you could tell me how you would approach it, in all its horrible detail :zzz::->:omg: Thanks!!!!!!!

    G Offline
    G Offline
    Grapes R Fun
    wrote on last edited by
    #6

    Nah, the Masterpage has nothing to do with this... just convert all your columns to templates (note that they will all default to Label controls; let me know if you need help with templated fields), then give your templated controls meaningful names. THEN you can access them like this: String _city; ... protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { ... Label city = (Label)(GridView1.SelectedRow.FindControl("cityLabel")); _city = city.Text; city.Dispose(); //yup, always clean up! TextBox copy = (TextBox)(GridView1.SelectedRow.FindControl("copyTextBox")); copy.Text = _city copy.Dispose(); } Give this a try. Let me know if it works ro not :-)

    Nila "...for that, I will need a large cup of coffee and a bran muffin!" -Samantha Bea

    M 2 Replies Last reply
    0
    • G Grapes R Fun

      Nah, the Masterpage has nothing to do with this... just convert all your columns to templates (note that they will all default to Label controls; let me know if you need help with templated fields), then give your templated controls meaningful names. THEN you can access them like this: String _city; ... protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { ... Label city = (Label)(GridView1.SelectedRow.FindControl("cityLabel")); _city = city.Text; city.Dispose(); //yup, always clean up! TextBox copy = (TextBox)(GridView1.SelectedRow.FindControl("copyTextBox")); copy.Text = _city copy.Dispose(); } Give this a try. Let me know if it works ro not :-)

      Nila "...for that, I will need a large cup of coffee and a bran muffin!" -Samantha Bea

      M Offline
      M Offline
      marconi Flangepants
      wrote on last edited by
      #7

      Thanks Nila, Ill give it a try today, and ill let you know how it goes! ;-)

      1 Reply Last reply
      0
      • G Grapes R Fun

        Nah, the Masterpage has nothing to do with this... just convert all your columns to templates (note that they will all default to Label controls; let me know if you need help with templated fields), then give your templated controls meaningful names. THEN you can access them like this: String _city; ... protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { ... Label city = (Label)(GridView1.SelectedRow.FindControl("cityLabel")); _city = city.Text; city.Dispose(); //yup, always clean up! TextBox copy = (TextBox)(GridView1.SelectedRow.FindControl("copyTextBox")); copy.Text = _city copy.Dispose(); } Give this a try. Let me know if it works ro not :-)

        Nila "...for that, I will need a large cup of coffee and a bran muffin!" -Samantha Bea

        M Offline
        M Offline
        marconi Flangepants
        wrote on last edited by
        #8

        Mate I Loves Ya! That works perfectly!!! Thanks a lot. But perhaps you can tell me 1 thing? Why does it only work when passing the Controls Data to a variable and then onto the static label control, yet it doesnt work when i miss out the middle man and try getting the data from the dynamic label and adding it straight to the static label? Thanks again. I appreciate your time!

        G 1 Reply Last reply
        0
        • M marconi Flangepants

          Mate I Loves Ya! That works perfectly!!! Thanks a lot. But perhaps you can tell me 1 thing? Why does it only work when passing the Controls Data to a variable and then onto the static label control, yet it doesnt work when i miss out the middle man and try getting the data from the dynamic label and adding it straight to the static label? Thanks again. I appreciate your time!

          G Offline
          G Offline
          Grapes R Fun
          wrote on last edited by
          #9

          Oh I have no idea why... typically when something doesn't work, I find a work around and move-on. Im sure the 'corky' .Net has its reasons, I just don't have time/patience to figure out the WHY ;-) Now, what does Mate I Loves Ya! mean??

          Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea

          M 1 Reply Last reply
          0
          • G Grapes R Fun

            Oh I have no idea why... typically when something doesn't work, I find a work around and move-on. Im sure the 'corky' .Net has its reasons, I just don't have time/patience to figure out the WHY ;-) Now, what does Mate I Loves Ya! mean??

            Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea

            M Offline
            M Offline
            marconi Flangepants
            wrote on last edited by
            #10

            Grapes-R-Fun wrote:

            Now, what does Mate I Loves Ya! mean??

            Ive no idea. Its a work around i use on my Girlfriend for most situations Babe, i love you! Likewise i dont understand women or what they want. lol!! :confused::laugh:

            G 1 Reply Last reply
            0
            • M marconi Flangepants

              Grapes-R-Fun wrote:

              Now, what does Mate I Loves Ya! mean??

              Ive no idea. Its a work around i use on my Girlfriend for most situations Babe, i love you! Likewise i dont understand women or what they want. lol!! :confused::laugh:

              G Offline
              G Offline
              Grapes R Fun
              wrote on last edited by
              #11

              LOL- are u flirting with me? :-O

              Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea

              M 1 Reply Last reply
              0
              • G Grapes R Fun

                LOL- are u flirting with me? :-O

                Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea

                M Offline
                M Offline
                marconi Flangepants
                wrote on last edited by
                #12

                Grapes-R-Fun wrote:

                are u flirting with me?

                I wasnt until i saw your pic on your profile!:->

                G 1 Reply Last reply
                0
                • M marconi Flangepants

                  Grapes-R-Fun wrote:

                  are u flirting with me?

                  I wasnt until i saw your pic on your profile!:->

                  G Offline
                  G Offline
                  Grapes R Fun
                  wrote on last edited by
                  #13

                  um, how did you see my pic? do you have one??;)

                  Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea

                  M 1 Reply Last reply
                  0
                  • G Grapes R Fun

                    um, how did you see my pic? do you have one??;)

                    Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea

                    M Offline
                    M Offline
                    marconi Flangepants
                    wrote on last edited by
                    #14

                    Your profile!

                    G 1 Reply Last reply
                    0
                    • M marconi Flangepants

                      Your profile!

                      G Offline
                      G Offline
                      Grapes R Fun
                      wrote on last edited by
                      #15

                      oh yeah, I figured how to see others' profiles as well... I am queen of the clueless nation!! why don't you put your pic up?

                      Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea

                      M 1 Reply Last reply
                      0
                      • G Grapes R Fun

                        oh yeah, I figured how to see others' profiles as well... I am queen of the clueless nation!! why don't you put your pic up?

                        Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea

                        M Offline
                        M Offline
                        marconi Flangepants
                        wrote on last edited by
                        #16

                        Grapes-R-Fun wrote:

                        why don't you put your pic up?

                        Are you flirting with me?

                        G 1 Reply Last reply
                        0
                        • M marconi Flangepants

                          Grapes-R-Fun wrote:

                          why don't you put your pic up?

                          Are you flirting with me?

                          G Offline
                          G Offline
                          Grapes R Fun
                          wrote on last edited by
                          #17

                          lol, maybe!

                          Nila I do ANYTHING for an extra large cup of coffee!

                          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