Gridview PostBack Problems

B

barrettenda

When a user selects an item from a dropdown list, the page is posted
back and the gridviews are binded to contain the new data because a new
parameter has been specified. But when I manually select a particular
row and cell using the code


for (int i = 0; i < GridView1.Rows.Count; i++)
{

GridViewRow row = GridView1.Rows;

temp = row.Cells[5].Text;

}

the value of temp is the old value before the page was posted back. I
am binding the gridview before I run the code above. I am really under
pressure to have this done for tomorrow. I just can't figure it out.
 
C

CaffieneRush

If you are talking of a master detail design like the first example on
http://www.asp.net/QuickStart/aspnet/doc/data/databases.aspx

Then try accessing the values within your gridview's databound event
handler.

Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GridView1.DataBound
For Each row As GridViewRow In GridView1.Rows
Dim cell1 As String = row.Cells(1).Text
Dim cell2 As String = row.Cells(2).Text
Next
End Sub
 
C

CaffieneRush

The master-detail design I was talking about in the above post can be
described as follows.
Master data control bound to -> Master data source.
Details data control bound to -> Details data source.
Details data source selected data controlled by -> master data source.

When a new value is selected in the master data control (dropdownlist
in this case) it changes the select parameter that the details data
source uses to select data on the next postback.

On the postback, the details data control (gridview in this case) has
it's data restored at first to the previous state (old values) - it is
only after it does a data bind on the details data source before the
new values is available in the details data control (gridview).

So if you check gridview's data on the postback during page init or
load, you will get the old data.
It's only after the details' DataBound event is raised before the new
values available.

Hope that helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top