Advertisement

[x]
Attachment Details

DataGrid paging not working (C#)

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4
I can sort columns fine ,but i get an error when i try to do built in paging. I tried everything. My other Datagrid events work fine

Code:

 <asp:DataGrid id="ProductDataGrid" OnPageIndexChanged="PageChangeClicked" OnItemCommand="DetailsClicked" OnSortCommand="SortEventHandler" style="Z-INDEX: 101; LEFT: 69px; POSITION: absolute; TOP: 80px" runat="server" Width="273px" Height="558px" AllowSorting="True" AllowPaging="True" AutoGenerateColumns="False" Font-Names="Arial Unicode MS" PageSize="15">
                <AlternatingItemStyle BackColor="#CCFF66"></AlternatingItemStyle>
                <Columns>
                    <asp:ButtonColumn Text="Details" ButtonType="PushButton" HeaderText="FAQ Details"></asp:ButtonColumn>
                    <asp:BoundColumn DataField="product_id" SortExpression="Manufacturer DESC" HeaderText="Product ID">
                        <HeaderStyle Font-Size="Large" Font-Underline="True" Font-Names="Book Antiqua" HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="Comments" HeaderText="Comments of power">
                        <HeaderStyle Font-Size="Large" Font-Underline="True" Font-Names="Book Antiqua" HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
                    </asp:BoundColumn>
                </Columns>
            </asp:DataGrid>



protected void PageChangeClicked(object sender, DataGridPageChangedEventArgs e)
        {
            ProductDataGrid.CurrentPageIndex = e.NewPageIndex;
       
            SqlConnection conn = null;
            conn = new SqlConnection("worksfine");
       
            String sqlSelect = "SELECT * FROM surplus_inventory";
            SqlDataAdapter dAdapt = new SqlDataAdapter(sqlSelect,conn);
            DataSet      myDS = new DataSet();
            dAdapt.Fill(myDS,"surplus_inventory");
       
            ProductDataGrid.DataSource = myDS;
            ProductDataGrid.DataBind();
        }




Error:(happens when I click on next link)


Server Error in '/SurplusInventory' Application.
--------------------------------------------------------------------------------

Specified argument was out of the range of valid values.
Parameter name: index
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.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index]
   System.Web.UI.ControlCollection.get_Item(Int32 index) +2057582
   System.Web.UI.WebControls.TableCellCollection.get_Item(Int32 index) +24
   SurplusInventory.DisplaySelectList.DetailsClicked(Object sender, DataGridCommandEventArgs e) +60
   System.Web.UI.WebControls.DataGrid.OnItemCommand(DataGridCommandEventArgs e) +105
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +77
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +117
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +163
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Related Solutions
Related Solutions
 
Loading Advertisement...
 
Expert Comment by kaflekk:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 

Rank: Master

Accepted Solution by MogalManic:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Author Comment by NESupply:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 

Rank: Master

Expert Comment by MogalManic:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
Loading Advertisement...
20080924-EE-VQP-40