Matias Folgar
Matias Folgar

Reputation: 51

GridView Selected Index Changed on different pages

I have a problem when I try to get value for a selectedIndexChanged that is on another page within the GridView.

protected void dgvViewGatesLive_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow row = dgvViewGatesLive.SelectedRow;
    if (row.Cells.Count >= 0)
    {
        Device = row.Cells[1].Text;
        Session["actualDevice"] = Device;
        //some code
        //
    }
}

the "Device" bring me the correct row but the data of the first page even if selectedIndexChanged is fired from another page of GridView for example:

if i select the first row from page 2 the code above brings me the device in the first row from page 1. HereDevice = row.Cells[1].Text;

EDIT 1:

I found the solution as pageload reloaded data in gridView. Needed to reload the current page and update control before using like this:

int page = (int)Session["Page"];
 dgvViewGatesLive.PageIndex = page;
 dgvViewGatesLive.DataBind();
 GridViewRow row = dgvViewGatesLive.SelectedRow;

Upvotes: 1

Views: 1690

Answers (2)

Matias Folgar
Matias Folgar

Reputation: 51

I found the solution as pageload reloaded data in gridView. Needed to reload the current page and update control before using like this:

int page = (int)Session["Page"];
 dgvViewGatesLive.PageIndex = page;
 dgvViewGatesLive.DataBind();
 GridViewRow row = dgvViewGatesLive.SelectedRow;

Upvotes: 1

Steve Wellens
Steve Wellens

Reputation: 20620

Do you have two GridViews?

I see you captured the index changed event on dgvViewGates.

But you are getting info from dgvViewGatesLive.

Upvotes: 0

Related Questions