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. Convert GridView To DataTable

Convert GridView To DataTable

Scheduled Pinned Locked Moved ASP.NET
cssquestion
4 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.
  • T Offline
    T Offline
    treuveni
    wrote on last edited by
    #1

    Hi, I have a grid with 10K rows and i'm trying to convert it to datatable. First Ex. DataTable dt = (DataTable)GridViewArgs.DataSource; Second Ex. DataView dataview = (DataView)GridViewArgs.DataSource; DataTable dt = dataview.Table.Clone(); In both ex. i got an empty datatable (the grid has values). Can someone please tell me what i'm doing wrong?

    A B A 3 Replies Last reply
    0
    • T treuveni

      Hi, I have a grid with 10K rows and i'm trying to convert it to datatable. First Ex. DataTable dt = (DataTable)GridViewArgs.DataSource; Second Ex. DataView dataview = (DataView)GridViewArgs.DataSource; DataTable dt = dataview.Table.Clone(); In both ex. i got an empty datatable (the grid has values). Can someone please tell me what i'm doing wrong?

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      treuveni wrote:

      I have a grid with 10K rows

      :doh: Which is not good design! Why 10 K Records in a grid? Does it really make any sense? It will hit your application performance very badly. Show only those data that are required. Use some filter to show less amount of data.

      treuveni wrote:

      DataTable dt = (DataTable)GridViewArgs.DataSource;

      What is your Source of Gridview data ?

      Cheers ! Abhijit Jana | My Blog | @Twitter | Disclaimer

      1 Reply Last reply
      0
      • T treuveni

        Hi, I have a grid with 10K rows and i'm trying to convert it to datatable. First Ex. DataTable dt = (DataTable)GridViewArgs.DataSource; Second Ex. DataView dataview = (DataView)GridViewArgs.DataSource; DataTable dt = dataview.Table.Clone(); In both ex. i got an empty datatable (the grid has values). Can someone please tell me what i'm doing wrong?

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        First example should works. Second example: DataView dataview = ((DataTable)GridViewArgs.DataSource).DefaultView;


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

        1 Reply Last reply
        0
        • T treuveni

          Hi, I have a grid with 10K rows and i'm trying to convert it to datatable. First Ex. DataTable dt = (DataTable)GridViewArgs.DataSource; Second Ex. DataView dataview = (DataView)GridViewArgs.DataSource; DataTable dt = dataview.Table.Clone(); In both ex. i got an empty datatable (the grid has values). Can someone please tell me what i'm doing wrong?

          A Offline
          A Offline
          Anurag Gandhi
          wrote on last edited by
          #4

          If you are trying to retrieve the data after postback, datasource will return null unless you bind the data again. If your GridView ViewState is not disabled, you can access the data by iterating rows and columns like this:

          foreach(GridViewRow row in grdRawData.Rows)
          {
          myData = row.Cells[ColNum].Text; // For BoundField only.//
          }

          If you are using controls, say TextBox, in GridView Columns, you can fetch the data by using FindControl method.

          TextBox txtName = (TextBox)grdRawData.Rows[rowNum].FindControl("IdOfTextBox"); // For BoundField only.//
          myData = txtName.Text;

          Hope this will help.

          Anurag Gandhi.
          http://www.gandhisoft.com
          Life is a computer program and every one is the programmer of his own life.
          My latest article: Group GridView Data

          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