How do I directly change the contents of a GridView cell from within a PageIndexChanged sub?

When I update the GridViewfrom within the click method of a Button on the page, it works perfectly fine.  It instantly updates the cell on the GridView.

However, when I page forward and put the same command into the PageIndexChanged  method for the GridView, nothing happens.  No error and no update to the GridView.

I have created a label and put a command in the PageIndexChanged call to display what is in the particular cell and it does indeed display the correct contents from the GridView.

I've looked at the MSDN documentation, I've googled for similar problems and found nothing.  I'm running Visual Studio 2008 Pro on Vista SP2.  Website (ajax enabled) is coded in VB.

Would really appreciate some pointers as to what I'm missing here to be able to edit the GridView from inside the PageIndexChanged sub.

Please ask for any info if I have missed anything vital.
GridView1.Rows(0).Cells(3).Text = "TEST" ' when this is inside a Button's onclick code, it works perfectly fine.
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged
GridView1.Rows(0).Cells(3).Text = "TEST" ' doesn't do anything at all - no errors either.
End Sub
'This is the code for the GridView in the .aspx file, if it is of any help:
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="GUID" 
                DataSourceID="SqlDataSource1" style="font-family: Arial; font-size: xx-small">
                            <asp:CheckBox ID="Selector" runat="server" AutoPostBack="true" OnCheckedChanged="sCheckedChanged" />
                    <asp:BoundField DataField="GUID" HeaderText="GUID" ReadOnly="True" 
                        SortExpression="GUID" Visible="False" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="MsrcSeverity" HeaderText="MsrcSeverity" 
                        SortExpression="MsrcSeverity" />
                    <asp:BoundField DataField="SupportUrl" HeaderText="SupportUrl" 
                        SortExpression="SupportUrl" />

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It's because after a page index change event occurs, the grid neeeds to rebind itself to the data source. You can use something like the c# code below on the data bound event to check if the rebind was due to a page event and set the cell text
public partial class _Default : System.Web.UI.Page
    bool pageHasChanged = false;
    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        pageHasChanged = true;
    protected void GridView1_DataBound(object sender, EventArgs e)
        if (pageHasChanged)
            this.GridView1.Rows[0].Cells[1].Text = "TEST"; // doesn't do anything at all - no errors either.

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
riverbankAuthor Commented:
Perfect.  That was just the pointer I needed, thanks.  I had a play around and eventually got it to work around what you suggested.  Really simple when you know how.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.