views:

142

answers:

2

Hi there

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 click 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
A: 

Are you databinding on every postback? That would be one cause of the requerying.

Matthew Jones
I am not sure what you mean...sorry, as I said, I am new at this :)What do you mean ? How do I stop it from databinding on every postback?
frank2009
A: 

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.

Chris
my apologies, but I am not sure where I have to put the code you mention...could you give me a hint ?
frank2009
Place that code in the page load event in your code behind.
Chris
Hi, this is the code I put on my page.I get no errors, so it's ok, however still doing postback when "select" link is clicked.Anything else missing ? Thanks for your response Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Gridview2.DataBind() End If End Sub
frank2009