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. How to GET GridView DataSource value?

How to GET GridView DataSource value?

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
9 Posts 5 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.
  • V Offline
    V Offline
    vicky457
    wrote on last edited by
    #1

    Hi, I am trying to access its datasouce property after the gridview has been databind, but the value is always null. here is the example I did: in button1_click: ... GridView1.DataSource = dataTable1; GridView1.DataBind(); .... in button2_click: .... DataTable dt = GridView1.DataSource; .... The value of dt in button2_Click is always null. I read about that the data source needs to be bound to the GridView control only when the page is first loaded. Thereafter, the values are stored in view state. How to access ViewState to get the data source property? Is there anybody know about it? Thanks in advance!

    E P M V 4 Replies Last reply
    0
    • V vicky457

      Hi, I am trying to access its datasouce property after the gridview has been databind, but the value is always null. here is the example I did: in button1_click: ... GridView1.DataSource = dataTable1; GridView1.DataBind(); .... in button2_click: .... DataTable dt = GridView1.DataSource; .... The value of dt in button2_Click is always null. I read about that the data source needs to be bound to the GridView control only when the page is first loaded. Thereafter, the values are stored in view state. How to access ViewState to get the data source property? Is there anybody know about it? Thanks in advance!

      E Offline
      E Offline
      ednrgc
      wrote on last edited by
      #2

      The datasource isn't maintained in viewstate as a raw dataset.

      1 Reply Last reply
      0
      • V vicky457

        Hi, I am trying to access its datasouce property after the gridview has been databind, but the value is always null. here is the example I did: in button1_click: ... GridView1.DataSource = dataTable1; GridView1.DataBind(); .... in button2_click: .... DataTable dt = GridView1.DataSource; .... The value of dt in button2_Click is always null. I read about that the data source needs to be bound to the GridView control only when the page is first loaded. Thereafter, the values are stored in view state. How to access ViewState to get the data source property? Is there anybody know about it? Thanks in advance!

        P Offline
        P Offline
        Pradipta Basu
        wrote on last edited by
        #3

        Datagrid is stored in a table, which is stored in ViewState. ViewState doesn't store the DataTable. only serialized data can be stored in viewstate.

        Pradipta Basu

        1 Reply Last reply
        0
        • V vicky457

          Hi, I am trying to access its datasouce property after the gridview has been databind, but the value is always null. here is the example I did: in button1_click: ... GridView1.DataSource = dataTable1; GridView1.DataBind(); .... in button2_click: .... DataTable dt = GridView1.DataSource; .... The value of dt in button2_Click is always null. I read about that the data source needs to be bound to the GridView control only when the page is first loaded. Thereafter, the values are stored in view state. How to access ViewState to get the data source property? Is there anybody know about it? Thanks in advance!

          M Offline
          M Offline
          Matt Ridley
          wrote on last edited by
          #4

          I think you may just have to cast the datasource to a datatable DataTable dt = (DataTable)GridView1.DataSource;

          V 1 Reply Last reply
          0
          • M Matt Ridley

            I think you may just have to cast the datasource to a datatable DataTable dt = (DataTable)GridView1.DataSource;

            V Offline
            V Offline
            vicky457
            wrote on last edited by
            #5

            I did try that. But it still is null..

            1 Reply Last reply
            0
            • V vicky457

              Hi, I am trying to access its datasouce property after the gridview has been databind, but the value is always null. here is the example I did: in button1_click: ... GridView1.DataSource = dataTable1; GridView1.DataBind(); .... in button2_click: .... DataTable dt = GridView1.DataSource; .... The value of dt in button2_Click is always null. I read about that the data source needs to be bound to the GridView control only when the page is first loaded. Thereafter, the values are stored in view state. How to access ViewState to get the data source property? Is there anybody know about it? Thanks in advance!

              V Offline
              V Offline
              vicky457
              wrote on last edited by
              #6

              I saved the datatable into viewstate when the GridView is binded. Then, when I want to use it, I just get it from viewState... Do you think it could cause any issue, like perfomance?

              I E 2 Replies Last reply
              0
              • V vicky457

                I saved the datatable into viewstate when the GridView is binded. Then, when I want to use it, I just get it from viewState... Do you think it could cause any issue, like perfomance?

                I Offline
                I Offline
                indianet
                wrote on last edited by
                #7

                Storing multiple rows or even a single row with considerable no. of columns is going to create an impact on the page's performance.

                V 1 Reply Last reply
                0
                • I indianet

                  Storing multiple rows or even a single row with considerable no. of columns is going to create an impact on the page's performance.

                  V Offline
                  V Offline
                  vicky457
                  wrote on last edited by
                  #8

                  to dynamically add rows into GridView without really adding records into database, so that user can add as many rows as he wants, and dump all the rows into db at once. Is there any other ideas to do it?

                  1 Reply Last reply
                  0
                  • V vicky457

                    I saved the datatable into viewstate when the GridView is binded. Then, when I want to use it, I just get it from viewState... Do you think it could cause any issue, like perfomance?

                    E Offline
                    E Offline
                    ednrgc
                    wrote on last edited by
                    #9

                    Remember that you're actually storing the datatable twice (in a sense). It's values are being stored in the viewstate inside the binded control, and you are storing it, as a whole, also. With minimal rows, this would be fine. But at the table grows, the viewstate grows twice as fast and could lead to major memory headaches down the road. You also have the option of turning off viewstate for the binded control. There are several articles explaining this process.

                    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