binding datatable to grid view

后端 未结 2 1263
挽巷
挽巷 2021-01-06 09:38

I have the following code:

Imports System.Data

Partial Class Students_AddWishes Inherits System.Web.UI.Page

    Public dt As New DataTable

    Protected S         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-06 10:20

    You need to save the datatable to Session, because local variables are not preserved. So you need to do:

    protected override OnLoad(..) //or OnInit
    {
       dt = Session["DataTable"] as DataTable;
       if (dt == null)
       {
           dt = new DataTable();
           //load columns
       }
    }
    
    protected override OnUnLoad(..)
    {
       Session["DataTable"] = dt;
    }
    

    Session saves the data table reference across postbacks as the web is stateless.

提交回复
热议问题