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 values + storing them in database

Gridview values + storing them in database

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestionannouncement
12 Posts 4 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 DKalepu

    Hi, I'm designing a online purchase form... i'm using gridview for this: here is my source code: below this i hv a "submit button". whenever user enter values in the textboxes & click on sumit button values should update in the database... how could I do that??.. Any one please help me. its urgent... Thanks in Advance.

    A Offline
    A Offline
    Amit Amit Amit
    wrote on last edited by
    #3

    U must have multiple rows in that GridView, so make a foreach loop like this. foreach (GridViewRow dgRow in myGridView1.Rows) { string strPK = myGridView1.DataKeys[dgRow.RowIndex].Value.ToString(); string str = ((TextBox)dgRow.FindControl("txtText")).Text.ToString(); //like this u will get all cells values and PK field .. //Now U can Update this data from Gridview of each row //to DataBase } :):):):):) Amit Metkar 3i-infotech, Mumbai.

    D 1 Reply Last reply
    0
    • N N a v a n e e t h

      DKalepu wrote:

      whenever user enter values in the textboxes & click on sumit button values should update in the database... how could I do that??

      GridView is having a method called FindControl() which finds the control specified from the grid view. So in your scenario, you need to find each textboxes from grid view and update to DB. TextBox txt = (TextBox) myGridView1.Rows[i].Cells[1].FindControl("txtPartNo"); This will give you the txtPartNo textbox object. Write code for all other controls like this.


      My Website | Ask smart questions

      A Offline
      A Offline
      Amit Amit Amit
      wrote on last edited by
      #4

      hi friend ur tring that method of updating the gridview data to database is applicable only on the gridview event. and the person who had this problem asking for getting data updated on external button_click to the gridview. so, see my reply, if u have any confusion @ this Dont mind please... :):):):):) Amit Metkar 3i-infotech, Mumbai.

      N 1 Reply Last reply
      0
      • A Amit Amit Amit

        U must have multiple rows in that GridView, so make a foreach loop like this. foreach (GridViewRow dgRow in myGridView1.Rows) { string strPK = myGridView1.DataKeys[dgRow.RowIndex].Value.ToString(); string str = ((TextBox)dgRow.FindControl("txtText")).Text.ToString(); //like this u will get all cells values and PK field .. //Now U can Update this data from Gridview of each row //to DataBase } :):):):):) Amit Metkar 3i-infotech, Mumbai.

        D Offline
        D Offline
        DKalepu
        wrote on last edited by
        #5

        Hi, Thanks for the help... should I write it in "button_click" event..?:confused: & also kindly plz tell me how to use the Update command to update database.... plz.. thanks in advance!

        A 1 Reply Last reply
        0
        • A Amit Amit Amit

          hi friend ur tring that method of updating the gridview data to database is applicable only on the gridview event. and the person who had this problem asking for getting data updated on external button_click to the gridview. so, see my reply, if u have any confusion @ this Dont mind please... :):):):):) Amit Metkar 3i-infotech, Mumbai.

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #6

          amit.metkar wrote:

          ur tring that method of updating the gridview data to database is applicable only on the gridview event. and the person who had this problem asking for getting data updated on external button_click to the gridview.

          Dear, Could you tell me how you judge this ? And please show me the difference between your and my code ? Only difference what I found is I given a hit, and you given entire code!. Actually my idea is just give a hint, why should I write entire code, it's like I doing his homework.


          My Website | Ask smart questions

          A 1 Reply Last reply
          0
          • N N a v a n e e t h

            amit.metkar wrote:

            ur tring that method of updating the gridview data to database is applicable only on the gridview event. and the person who had this problem asking for getting data updated on external button_click to the gridview.

            Dear, Could you tell me how you judge this ? And please show me the difference between your and my code ? Only difference what I found is I given a hit, and you given entire code!. Actually my idea is just give a hint, why should I write entire code, it's like I doing his homework.


            My Website | Ask smart questions

            A Offline
            A Offline
            Amit Amit Amit
            wrote on last edited by
            #7

            there is much more difference in ur code and my code it is not like ur giving him just the hint and i m giving him the entire code OR homework. UR CODE -- for the external button click which is not in gridview, so in this situation u can not get row index , this is the biggest problem in ur code, i m not saying that ur code was wrong. MY CODE -- I get the Row index thro' GridViewRow Object. And one by one i can retrieve all rows and their cells values. :-D:):-D:):-D Amit Metkar 3i-infotech, Mumbai.

            N 1 Reply Last reply
            0
            • A Amit Amit Amit

              there is much more difference in ur code and my code it is not like ur giving him just the hint and i m giving him the entire code OR homework. UR CODE -- for the external button click which is not in gridview, so in this situation u can not get row index , this is the biggest problem in ur code, i m not saying that ur code was wrong. MY CODE -- I get the Row index thro' GridViewRow Object. And one by one i can retrieve all rows and their cells values. :-D:):-D:):-D Amit Metkar 3i-infotech, Mumbai.

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #8

              amit.metkar wrote:

              UR CODE -- for the external button click which is not in gridview, so in this situation u can not get row index , this is the biggest problem in ur code, i m not saying that ur code was wrong.

              Again you are misunderstanding me, I think you are confused with that variable i, right ? I am very lazy to type X| X| , so I didn't type the loop That's it. Anyway good suggestion, Thanks


              My Website | Ask smart questions

              A 1 Reply Last reply
              0
              • N N a v a n e e t h

                DKalepu wrote:

                whenever user enter values in the textboxes & click on sumit button values should update in the database... how could I do that??

                GridView is having a method called FindControl() which finds the control specified from the grid view. So in your scenario, you need to find each textboxes from grid view and update to DB. TextBox txt = (TextBox) myGridView1.Rows[i].Cells[1].FindControl("txtPartNo"); This will give you the txtPartNo textbox object. Write code for all other controls like this.


                My Website | Ask smart questions

                D Offline
                D Offline
                DKalepu
                wrote on last edited by
                #9

                Hi Navneeth, Thanks for the help! this piece of code solved my problem! thanks once again!:)

                1 Reply Last reply
                0
                • D DKalepu

                  Hi, Thanks for the help... should I write it in "button_click" event..?:confused: & also kindly plz tell me how to use the Update command to update database.... plz.. thanks in advance!

                  A Offline
                  A Offline
                  Amit Amit Amit
                  wrote on last edited by
                  #10

                  Yes, u can write that in "button_click" event. and @ ur second Q, can u clarify it,i mean explain it little, i m not getting wat u want? Amit Metkar 3i-infotech, Mumbai.

                  1 Reply Last reply
                  0
                  • N N a v a n e e t h

                    amit.metkar wrote:

                    UR CODE -- for the external button click which is not in gridview, so in this situation u can not get row index , this is the biggest problem in ur code, i m not saying that ur code was wrong.

                    Again you are misunderstanding me, I think you are confused with that variable i, right ? I am very lazy to type X| X| , so I didn't type the loop That's it. Anyway good suggestion, Thanks


                    My Website | Ask smart questions

                    A Offline
                    A Offline
                    Amit Amit Amit
                    wrote on last edited by
                    #11

                    Ohhh Dear, Sorry @ that, but a small thing can make things differ. Okay dear, Nice to talk with u.. :-D:-D:-D Amit Metkar 3i-infotech, Mumbai.

                    1 Reply Last reply
                    0
                    • D DKalepu

                      Hi, I'm designing a online purchase form... i'm using gridview for this: here is my source code: below this i hv a "submit button". whenever user enter values in the textboxes & click on sumit button values should update in the database... how could I do that??.. Any one please help me. its urgent... Thanks in Advance.

                      C Offline
                      C Offline
                      chapathi
                      wrote on last edited by
                      #12

                      dont use external button... the thing ur doing is inbuild so use the smart tag and add or edit colums in that watever thing u needed just add it weather its edit r update r any thing else and in the fireevent write the coding.. i think tis will help u

                      vivek nanda

                      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