DataGrid paging problem ....need to click twice...why?

hai everyone
i am making use of datagrid and allowing paging but i am facing a small problem
when i am clicking on the page no the datagrid is not refreshed ..in order to

refresh it i need to click on the page no one more time now the grid shows the

proper page ??
this is the code inside the pageindexchanged eventhandler
================================================================
code
=====================================================================
private void DataGrid1_PageIndexChanged(object source,

System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
Response.Write(e.NewPageIndex);
DataGrid1.CurrentPageIndex=e.NewPageIndex;

Response.Write(DataGrid1.CurrentPageIndex);
}
=======================================================================

can any one suggest what is that i am missing or any alternative solution

thanks in advance..
austinhere is some code I have used in the past, but it is in vb.net.

Sub Page_Load(Src As Object, E As EventArgs)
If Not Page.IsPostBack then
BindData()
End If
end sub
Sub BindData()
Dim DBConn as OleDbConnection
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("/yourdb.mdb;"))
Dim strSQL As String
strSQL = "Select *, * from * order by * desc"
Dim AdapterDockets As OleDbDataAdapter
Dim DataSetDockets As DataSet
AdapterDockets = New OleDbDataAdapter(strSQL, dbconn)
DataSetDockets = New DataSet()
AdapterDockets.Fill(DataSetDockets)
ContentGrid.DataSource = DataSetDockets
ContentGrid.DataBind()
End Sub
Sub ContentGrid_PageChanger(ByVal Source As Object, ByVal E As DataGridPageChangedEventArgs)
ContentGrid.CurrentPageIndex = E.NewPageIndex
BindData()
end sub


This will need to be in the grid, this might be what is going wrong for you, this not being in the grid.

OnPageIndexChanged="ContentGrid_PageChanger"when you are in the Page Changed event you should rebind your datagrid so that it can render the correct page.

private void DataGrid1_PageIndexChanged(object source,

System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
Response.Write(e.NewPageIndex);
DataGrid1.CurrentPageIndex=e.NewPageIndex;
DataGrid1.DataSource = something;
DataGrid1.DataBind();
Response.Write(DataGrid1.CurrentPageIndex);
}

And I would think that your event should be protected unless it is in the Page code itself, but if the event is actually firing, then don't worry about the protected instead of private.

Ben Millerhai all
i was missing the statement to sepicify the data source of the datagrid again in the pagechange event

thank all
keep smiling
austin
 
Back
Top