从下面的代码// Doing some operations
开始,页面加载时需要几秒钟,大概30到40秒。然后我打电话给Method()
。当我单击索引4(GridView中的页码4)页面时,为了显示页码4,它也占用相同的时间(30到40秒)。但我真的很需要它。我该如何更改代码? VB.NET中的代码
Protected Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
// Doing some operations
Method()
End Sub
Protected Sub GridView1_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
Private Sub Method()
Dim sqlConnect As SqlConnection = New SqlConnection(Connection String)
Dim adapter As New SqlDataAdapter
Dim ds As DataSet
Dim sqlString = "SELECT * FROM Table"
Dim Command As SqlCommand = New SqlCommand(sqlString, sqlConnect)
adapter.SelectCommand = Command
adapter.Fill(ds)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
End Sub