Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2005, 01:38 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Spacy,

I have solved 1st problem, as stated in my previous post.
Now, the only problem is, I can't view the 2nd page onwards.

Code:
  Private Sub DataGrid1_PageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        Try
            DataGrid1.CurrentPageIndex = e.NewPageIndex
            DataGrid1.DataBind()
        Catch ex As Exception
            Dim a As String
            a = ex.Message
        End Try

    End Sub 

 Private Sub ddlView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlView1.SelectedIndexChanged
        Dim Str As String
        Str = "Select * From Library where CategoryID = " & ddlView1.SelectedValue
        SqlDataAdapter1.SelectCommand.CommandText = Str
        SqlDataAdapter1.Fill(DsLibrary1)
        DataGrid1.DataSource = DsLibrary1
        DataGrid1.DataMember = "Library"
        DataGrid1.DataBind()
End Sub



 
Old June 8th, 2005, 02:08 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My last post is a solution for your problem with 2nd page onwards.

This:
        DataGrid1.CurrentPageIndex = e.NewPageIndex
        DataGrid1.DataBind()

wont work as you have not specified what to bind to the datagrid.
Thats the reason for the blank page.
Store the ddlView1.SelectedValue in a global variable.

Private Sub DataGrid1_PageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles DataGrid1.PageIndexChanged
        Try
            DataGrid1.CurrentPageIndex = e.NewPageIndex
             Dim Str As String
        Str = "Select * From Library where CategoryID = " & globalVar
        SqlDataAdapter1.SelectCommand.CommandText = Str
        SqlDataAdapter1.Fill(DsLibrary1)
        DataGrid1.DataSource = DsLibrary1
        DataGrid1.DataMember = "Library"
        DataGrid1.DataBind()

        Catch ex As Exception
            Dim a As String
            a = ex.Message
        End Try

    End Sub

Hope this helps.

Cheers..
Spacy...

 
Old June 8th, 2005, 02:27 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Or else you can put the connection code in a procedure:

Private Sub BindGrid()
         Dim Str As String
        Str = "Select * From Library where CategoryID = " & ddlView1.SelectedValue
        SqlDataAdapter1.SelectCommand.CommandText = Str
        SqlDataAdapter1.Fill(DsLibrary1)
        DataGrid1.DataSource = DsLibrary1
        DataGrid1.DataMember = "Library"
        DataGrid1.DataBind()

    End Sub

Private Sub DataGrid1_PageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles DataGrid1.PageIndexChanged
        Try
            DataGrid1.CurrentPageIndex = e.NewPageIndex
            BindGrid()
        Catch ex As Exception
            Dim a As String
            a = ex.Message
        End Try

    End Sub

 Private Sub ddlView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlView1.SelectedIndexChanged
       BindGrid()
 End Sub



 
Old June 8th, 2005, 04:12 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Spacy, now I use ur 2nd suggestion. i.e when i select
Books, the data is displayed, then I navigate through the records.
But when I select Journals, the following error is displayed.

Server Error in '/e-library' Application.
--------------------------------------------------------------------------------

Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.

Source Error:


Line 219: DataGrid1.DataSource = DsLibrary1
Line 220: DataGrid1.DataMember = "Library"
Line 221: DataGrid1.DataBind()
Line 222: End Sub
Line 223:


Source File: c:\inetpub\wwwroot\e-library\Borrow.aspx.vb Line: 221

Stack Trace:


[HttpException (0x80004005): Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.]
   System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean useDataSource)
   System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e)
   System.Web.UI.WebControls.BaseDataList.DataBind()
   e_library.Borrow.BindGrid() in c:\inetpub\wwwroot\e-library\Borrow.aspx.vb:221
   e_library.Borrow.ddlView1_SelectedIndexChanged(Obj ect sender, EventArgs e) in c:\inetpub\wwwroot\e-library\Borrow.aspx.vb:135
   System.Web.UI.WebControls.ListControl.OnSelectedIn dexChanged(EventArgs e)
   System.Web.UI.WebControls.DropDownList.System.Web. UI.IPostBackDataHandler.RaisePostDataChangedEvent( )
   System.Web.UI.Page.RaiseChangedEvents()
   System.Web.UI.Page.ProcessRequestMain()

I don't understand why it happens.

Thanks!



 
Old June 8th, 2005, 04:42 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default


You need to reset the currentpage index every time your selection changes.

 Private Sub ddlView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlView1.SelectedIndexChanged
       DataGrid1.CurrentPageIndex = 0
       BindGrid()
 End Sub

Cheers..
Spacy...




 
Old June 8th, 2005, 06:17 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Spacy, I solved the problem already.

 
Old January 31st, 2006, 11:48 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

People have spent so much time and energy trying to help you solve your problem.

As a common courtesy, please post your solution.

 
Old November 14th, 2006, 02:17 AM
Registered User
 
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to meetvedant
Default

reset the currentpage index tpo 0

protected void DropDown_SelectedIndexChanged(object sender, EventArgs e)
 {
      GataGrid.CurrentPageIndex = 0;
  }

Regards,
Rajesh Sawant






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with binding data in Datagrid Samatha ASP.NET 1.0 and 1.1 Professional 6 December 6th, 2006 09:13 AM
Datagrid binding two dropdown inkrajesh ASP.NET 1.0 and 1.1 Basics 0 July 18th, 2006 10:46 PM
Binding Data to a DataGrid RPG SEARCH ASP.NET 1.0 and 1.1 Basics 5 August 9th, 2004 02:27 PM
DataGrid Binding GrindCrusher Classic ASP Databases 0 February 21st, 2004 05:52 PM
Binding an aarraylist to a datagrid Delano ADO.NET 2 September 22nd, 2003 05:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.