English 中文(简体)
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 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
问题回答

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.





相关问题
asp.net gridview editindex

Please take a look at this: protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int index = Convert.ToInt32(e.CommandArgument); if (e.CommandName == "Edit") {...

How do I stop my gridview from caching?

I search for results, click one, it opens in a new window, then edit it, and close the popup. Then I hit search to refresh my gridview, but the changes do not reflect unless I hit F5. It s caching ...

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/...

WPF GridView, Display GetType().Name in DisplayMemberBinding

I want include the Type name of each object in my collection from my GridView. I have a collection which has four different types in it that all derive from a base class. Call them, Foo, Bar, Fizz, ...

GridView that toggles percentages of counts

I am using a SqlDataSource that returns a table of raw counts. One of these columns is the "total". I would like to give the user the ability to show these counts as a percentage of total using some ...

热门标签