get data from gridview without querying database
I am new at this so please bear with me...
I have managed to get the following code to work...so when I click on the "select" link in each row of the gridview, the data is transfered to other label/textbox on the webpage.
So far so good, the thing is that everytime I cl开发者_高级运维ick on select...it goes and checks on the database for the data and there is a delay of a few seconds... I was hoping that the data, since it is already visible on the gridrows, is simply "picked up" and used on other labels/textboxes...without requerying the database.
Is this possible ? Thanks in advance
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = GridView2.SelectedRow.Cells(8).Text
Label2.Text = GridView2.SelectedRow.Cells(9).Text
TextBox1.Text = GridView2.SelectedRow.Cells(7).Text
End Sub
Are you databinding on every postback? That would be one cause of the requerying.
You might want to use this code at the point where you're binding to your grid.
If Not IsPostBack Then
Grid.DataBind()
End If
This way you will only bind the grid once when the page first loads.
Hope this helps.
精彩评论