Question

I have a gridview that is used to update a database. I am having a problem with the display at startup. The problem is that the page index should be 0 indicating that the gridview should start on the first page.

Here is what I thought should work:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gvSummary.PageIndex = 0;
            gvSummary.DataBind();
            this.BindData();
            dlAnnoType.SelectedValue = "Agency Error";

        }
    }

The page is going to whatever I had left off at in the previous session. I am hoping I can resolve this because I am using similar logic after I update a row in the gridview. According to the people who are checking my work, I have not accomplished this. I need to default to the first page on start and retain the page after update. Thanks in advance for any assistance.

Was it helpful?

Solution

You will have to check what the BindData function actually does. I think it is populating the GridView from a Sesssion and setting the PageIndex. Try setting the PageIndex after binding the GridView like this

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindData();
        gvSummary.PageIndex = 0;
        gvSummary.DataBind();
        dlAnnoType.SelectedValue = "Agency Error";

    }
}

P.S: this is not needed here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top