pageindex changed event in gridview

binay00713

Broken In
How to handle the pageindexChanged in gridview in asp.net
in the following code?

protected void Page_Load(object sender, EventArgs e)
{
ob.conn();
gridview();

}
public void gridview()
{
ob.grdv("select * from user_album where user_id='" + Session["user_id"].ToString() + "'", GridView1);


}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
gridview();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
gridview();
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
if (GridView1.EditIndex!=-1)
{
// Use the Cancel property to cancel the paging operation.
e.Cancel = true;

// Display an error message.
int newPageNumber = e.NewPageIndex + 1;
Response.Write("<script>alert('Please update the record before moving to page')</script>");
}
else
{
// Clear the error message.

}
}
protected void GridView1_PageIndexChanged(object sender, EventArgs e)
{
what to write here show that is goes to the page number clicked...
}
 
1. how many records does ob.grdv fetch?
2. what is the no of lines of the gridview?

if paging is enabled for gridview and 1 > 2 . then you wont have to write any code for GridView1_PageIndexChanged

do i explain myself ??
 
OP
B

binay00713

Broken In
1. how many records does ob.grdv fetch?
2. what is the no of lines of the gridview?

if paging is enabled for gridview and 1 > 2 . then you wont have to write any code for GridView1_PageIndexChanged

do i explain myself ??

ob.grdv fetches 6 records and no. of lines of the gridview is 3
paging is enabled (AllowPaging=""true")
still not going to next page..
what is 1>2 ? i cant understand .please explain
 
^^ not to worry. you answered my question.

one more thing ::
what exactly does // Clear the error message. does??

in addition what it does, try to insert the lines that are in bold

Code:
......
......            
.....
     Response.Write("<script>alert('Please update the record before moving to page')</script>");
        }
        else
        {
            // Clear the error message.
             ......
             ......
                       
            [B]//finally going to the next page
            GridView1.PageIndex = e.NewPageIndex;
            gridview();[/B]
        }
    }
    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        //what to write here show that is goes to the page number clicked...
    }
}

does that help ???
 
Top Bottom