Datagrid losing source between postbacks
-
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?
-
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?
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 ...[^]
-
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?
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