Usually this happens because you are not rebinding the grid to the
datasource when you post back on the paging button click. Could also
be you are setting (or failing to set) a legal value.
Here is the code-behind for a simple page that does grid paging.
Note, this example hits the db on every click. To avoid this you could
store the DataSet in a session variable or in the cache and set up
GetCustomer to get the value there before calling teh db.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn.Click
dg.CurrentPageIndex = 0
BindGrid()
End Sub
Private Sub BindGrid()
dg.DataSource = GetCustomer()
dg.DataBind()
End Sub
Private Function GetCustomer() As DataTable
Dim SQL As String
Dim WHERE As String = ""
SQL = "SELECT * FROM Customers"
If txtFirst.Text.Length > 0 Then
WHERE = " WHERE FirstName LIKE '%" & txtFirst.Text & "%'"
End If
If txtLast.Text.Length > 0 Then
If WHERE.Length = 0 Then
WHERE = " WHERE "
Else
WHERE &= " AND "
End If
WHERE &= "LastName LIKE '%" & txtLast.Text & "%'"
End If
Dim conn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("connString"))
Dim cmd As SqlCommand = New SqlCommand(SQL & WHERE, conn)
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable
da.Fill(dt)
Return dt
End Function
Private Sub dg_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
dg.PageIndexChanged
dg.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
On 10/11/05, Steven McConaughy <[EMAIL PROTECTED]> wrote:
> I have a datagrid on my page that uses a dataset generated from a data
> adapter. I use the Next/Previous method of scanning through the records. I
> have tried EVERY method mentioned on the internet and I still get the
> error in the subject. I am at witts end. I don't understand.
>
> Steven
>
>
>
> __________________________________
> Yahoo! Music Unlimited
> Access over 1 million songs. Try it free.
> http://music.yahoo.com/unlimited/
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/