By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

Datagrid navigation problem

P: n/a
Hello there,
Just a small problem while navigating datagrid, i am filling a datagrid by
output of query. i have given navigation buttons first,last, next,
previous.it is working but the problem is that i have to click twice to
navigate.any suggestion. i m using following code
Private Sub NavigationButtonClicked(ByVal sender As Object, _ByVal e As
EventArgs) Handles FirstPage.Click, PreviousPage.Click, NextPage.Click,
LastPage.Click Dim direction As String = CType(sender, Button).CommandName
Select Case direction.ToUpper() Case "FIRST"
DataGrid1.CurrentPageIndex = 0 Case "PREVIOUS"
DataGrid1.CurrentPageIndex = _ Math.Max(0,
DataGrid1.CurrentPageIndex - 1) Case "NEXT"
DataGrid1.CurrentPageIndex = _ Math.Min(DataGrid1.PageCount - 1,
_ DataGrid1.CurrentPageIndex + 1) Case "LAST"
DataGrid1.CurrentPageIndex = _ DataGrid1.PageCount - 1 Case
Else End Select DataGrid1.DataBind()End Sub
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi anand,

Check to see you are only binding the datagrid in the page_load if its not
postback

in Page_Load do databinding only if
if(!Page.IsPostBack)
{
DataGrid1.Datasource = yourdatasource;
DataGrid1.DataBind();
}
Regards
Ashish M Bhonkiya

"anand" <an****@armour.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hello there,
Just a small problem while navigating datagrid, i am filling a datagrid by output of query. i have given navigation buttons first,last, next,
previous.it is working but the problem is that i have to click twice to
navigate.any suggestion. i m using following code
Private Sub NavigationButtonClicked(ByVal sender As Object, _ByVal e As
EventArgs) Handles FirstPage.Click, PreviousPage.Click, NextPage.Click,
LastPage.Click Dim direction As String = CType(sender, Button).CommandName Select Case direction.ToUpper() Case "FIRST"
DataGrid1.CurrentPageIndex = 0 Case "PREVIOUS"
DataGrid1.CurrentPageIndex = _ Math.Max(0,
DataGrid1.CurrentPageIndex - 1) Case "NEXT"
DataGrid1.CurrentPageIndex = _ Math.Min(DataGrid1.PageCount - 1, _ DataGrid1.CurrentPageIndex + 1) Case "LAST"
DataGrid1.CurrentPageIndex = _ DataGrid1.PageCount - 1 Case Else End Select DataGrid1.DataBind()End Sub

Nov 18 '05 #2

P: n/a
thanks there , i tried but seems not working.any work around
"Ashish M Bhonkiya" <bh******@hotmail.com.nospam> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Hi anand,

Check to see you are only binding the datagrid in the page_load if its not postback

in Page_Load do databinding only if
if(!Page.IsPostBack)
{
DataGrid1.Datasource = yourdatasource;
DataGrid1.DataBind();
}
Regards
Ashish M Bhonkiya

"anand" <an****@armour.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hello there,
Just a small problem while navigating datagrid, i am filling a datagrid by
output of query. i have given navigation buttons first,last, next,
previous.it is working but the problem is that i have to click twice to
navigate.any suggestion. i m using following code
Private Sub NavigationButtonClicked(ByVal sender As Object, _ByVal e As
EventArgs) Handles FirstPage.Click, PreviousPage.Click, NextPage.Click,
LastPage.Click Dim direction As String = CType(sender,

Button).CommandName
Select Case direction.ToUpper() Case "FIRST"
DataGrid1.CurrentPageIndex = 0 Case "PREVIOUS"
DataGrid1.CurrentPageIndex = _ Math.Max(0,
DataGrid1.CurrentPageIndex - 1) Case "NEXT"
DataGrid1.CurrentPageIndex = _

Math.Min(DataGrid1.PageCount - 1,
_ DataGrid1.CurrentPageIndex + 1) Case "LAST"
DataGrid1.CurrentPageIndex = _ DataGrid1.PageCount - 1

Case
Else End Select DataGrid1.DataBind()End Sub


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.