Wrox Programmer Forums
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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 August 27th, 2004, 05:14 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page index error

I have designed a datagrid and set the paging=true, by default displaying 10 rows in one page. I am updating the status of the records and the rows are getting disappeared from the datagrid. My problem is when the last record of the page is disabled and disappearing the row i am getting error "System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount"

I have given the properties of datagrid in design as :-

<asp:datagrid id="DataGrid1" runat="server" datakeyfield="nExperienceId" EditItemStyle-ForeColor="black" EditItemStyle-BackColor="#ff6600" GridLines="Both" BorderWidth="0px" BorderStyle="Inset" ShowHeader="True" ItemStyle-BackColor="#ffcc99" HeaderStyle-ForeColor="#ffffff" HeaderStyle-BackColor="#ff6600" AlternatingItemStyle-BackColor="#ff9966" BorderColor="#E0EDF4" CellSpacing="1" CellPadding="5" AutoGenerateColumns="False" Width="537px" AllowSorting="True" background="imgs/blue_middle.gif" BackColor="Red" AllowPaging="True" PagerStyle-HorizontalAlign="Right">
<PagerStyle Mode="NumericPages"></PagerStyle>

And in code behind i have written as
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
        {
            DataGrid1.CurrentPageIndex = e.NewPageIndex;

        }


Can anyone help me?






 
Old August 27th, 2004, 06:20 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

change your algoritm of deleting the rows.
(I mean you can delete all the rows in dataset(or in your datasource)then again bind your grid).


--------------------------------------------
Mehdi.:)
 
Old August 27th, 2004, 06:25 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After updating the data I am binding it but the same error is coming.

 
Old August 27th, 2004, 07:16 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

not only binding,you should also fill your datasource again,
although this error tells you CurrentPageIndex has a negative value.


--------------------------------------------
Mehdi.:)
 
Old August 30th, 2004, 01:10 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mehdi,
Thanks u replied. But i am filling the datagrid as well as binding. But after the last record getting updated same error is coming.

 
Old August 30th, 2004, 02:38 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
as I told you if you do these steps correctly you should not face this problem
1-delete the row(s) from datasource(or your probable dataset)in any order
2-change the datasource of your grid
3-bind your grid
finally your datasource is empty and your grid doesnt show any filed without any error
I dont know exactly how you delete the rows ...
anyway try this optional way for avoiding this error...
Code:
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
  if((e.NewPageIndex>=0) & (e.NewPageIndex<=DataGrid1.PageCount))
            DataGrid1.CurrentPageIndex = e.NewPageIndex;
  else
            DataGrid1.CurrentPageIndex =0;
}
HtH.

--------------------------------------------
Mehdi.:)
 
Old August 31st, 2004, 01:55 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried with this but getting the same error.I used like this

private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
        {
            if((e.NewPageIndex>=0) & (e.NewPageIndex<=DataGrid1.PageCount))
            {
                DataGrid1.CurrentPageIndex = e.NewPageIndex;
                                BindData();

            }
            else
            {
                DataGrid1.CurrentPageIndex =0;
                                BindData();


            }
        }

Actually i am not exactly deleting, i have retrieved the values in the datagrid based on the status=0 and updating the status=1 after clicking the link given on the values at datagrid.After updating the status into 1 its getting disappeared from the datagrid,as the status changes.But after the last record getting updated this error comes.
I am really tried a lot and stuck up here.


 
Old August 31st, 2004, 11:19 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

change it like below ....
Code:
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {
if((e.NewPageIndex>=0) & (e.NewPageIndex<DataGrid1.PageCount))
            {
                DataGrid1.CurrentPageIndex = e.NewPageIndex;  
            }
            else
            {
                DataGrid1.CurrentPageIndex =0;
            }
        BindData();
        }
HtH.

--------------------------------------------
Mehdi.:)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2, page 33, SDK index? ag2000 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 0 July 13th, 2006 05:21 PM
chapter 13 building an index page drb2k2 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 5 March 5th, 2006 07:22 PM
Index page for reports miaminemo BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 January 11th, 2006 09:31 AM
Ch 2 Page 53: Undefined index: authuser Airidh BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 25 February 22nd, 2005 07:34 PM
How to keep url end w/ index.htm when page change bekim HTML Code Clinic 3 January 25th, 2005 05:00 PM





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