After you update the PageIndex
you need to rebind the grid, like this:
protected void ddlPaging_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.PageIndex = ddlPageNumber.SelectedIndex;
GridView1.DataBind();
}
UPDATE:
Since you are dynamically building the drop down list items for the page numbers, then you need to re-build them whenever a post back to the server happens or whenever the grid is rebound, like this:
private void BuildPageNumbers()
{
ddlPageNumber.Items.Clear();
for (int cnt = 0; cnt < GridView1.PageCount; cnt++)
{
int curr = cnt + 1;
ListItem item = new ListItem(curr.ToString());
if (cnt == GridView1.PageIndex)
{
item.Selected = true;
}
ddlPageNumber.Items.Add(item);
}
}
Now in your DataBound
and Page_Load
events, you can call this method, like this:
protected void Page_Load(object sender, EventArgs e)
{
BuildPageNumbers();
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
BuildPageNumbers();
}