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. Datagrid losing source between postbacks

Datagrid losing source between postbacks

Scheduled Pinned Locked Moved ASP.NET
questionworkspace
3 Posts 3 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.
  • C Offline
    C Offline
    Craigpt
    wrote on last edited by
    #1

    I have a datagrid, that gets setup with this function: Private Function SetupExamGrid() As DataTable If Not dgExam.DataSource Is Nothing Then DVTemp = dgExam.DataSource Else DTTemp = New DataTable DTTemp.Columns.Add(New DataColumn("exam", GetType(String))) DTTemp.Columns.Add(New DataColumn("crse_cd", GetType(String))) DTTemp.Columns.Add(New DataColumn("exam_ty", GetType(String))) DVTemp = New DataView(DTTemp) End If dgExam.DataSource = DVTemp dgExam.DataBind() End Function DVTemp is a dataview, created using DTtemp, which is a datatable. Both DVTemp and DTTemp are stored class-scope. I have enableViewState = True on the datagrid, but for some reason i'm losing the value stored in both DVTemp and DTTemp between postbacks. When i break it in the page.load sub, both variables are set to nothing, even though there was actual info in the source. Any ideas?

    M P 2 Replies Last reply
    0
    • C Craigpt

      I have a datagrid, that gets setup with this function: Private Function SetupExamGrid() As DataTable If Not dgExam.DataSource Is Nothing Then DVTemp = dgExam.DataSource Else DTTemp = New DataTable DTTemp.Columns.Add(New DataColumn("exam", GetType(String))) DTTemp.Columns.Add(New DataColumn("crse_cd", GetType(String))) DTTemp.Columns.Add(New DataColumn("exam_ty", GetType(String))) DVTemp = New DataView(DTTemp) End If dgExam.DataSource = DVTemp dgExam.DataBind() End Function DVTemp is a dataview, created using DTtemp, which is a datatable. Both DVTemp and DTTemp are stored class-scope. I have enableViewState = True on the datagrid, but for some reason i'm losing the value stored in both DVTemp and DTTemp between postbacks. When i break it in the page.load sub, both variables are set to nothing, even though there was actual info in the source. Any ideas?

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, The page instace will discarded when the life cycle of it finishes, so when the page posts back you will see those variables reset to null(nothing in VB) For more information, you can see Web Forms Page Processing[^] Also, it seems to me that you're new to the DataGrid web control (sorry if I'm wrong), you can get started with the documents: DataGrid Web Server Control[^] An example ...[^]

      1 Reply Last reply
      0
      • C Craigpt

        I have a datagrid, that gets setup with this function: Private Function SetupExamGrid() As DataTable If Not dgExam.DataSource Is Nothing Then DVTemp = dgExam.DataSource Else DTTemp = New DataTable DTTemp.Columns.Add(New DataColumn("exam", GetType(String))) DTTemp.Columns.Add(New DataColumn("crse_cd", GetType(String))) DTTemp.Columns.Add(New DataColumn("exam_ty", GetType(String))) DVTemp = New DataView(DTTemp) End If dgExam.DataSource = DVTemp dgExam.DataBind() End Function DVTemp is a dataview, created using DTtemp, which is a datatable. Both DVTemp and DTTemp are stored class-scope. I have enableViewState = True on the datagrid, but for some reason i'm losing the value stored in both DVTemp and DTTemp between postbacks. When i break it in the page.load sub, both variables are set to nothing, even though there was actual info in the source. Any ideas?

        P Offline
        P Offline
        P A N K A J
        wrote on last edited by
        #3

        hello i think you declare the dataset or datatable as global so every post they blanks.......... one way to declare them as in the same function....... bye pankaj

        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