How to GET GridView DataSource value?
-
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!
-
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!
-
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!
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
-
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!
I think you may just have to cast the datasource to a datatable DataTable dt = (DataTable)GridView1.DataSource;
-
I think you may just have to cast the datasource to a datatable DataTable dt = (DataTable)GridView1.DataSource;
-
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!
-
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?
-
Storing multiple rows or even a single row with considerable no. of columns is going to create an impact on the page's performance.
-
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?
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.