473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

GridView And PageIndexChanging

69
Hi Guys,

I have a problem. I have a gridview that is bound to a SQLDataSource using a stored procedure that is used for Searching. it works fine. my problem is that if I select a page index, the grid view disappears.

This is the code for my GridView and datasource
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="afGridView" runat="server" AllowPaging="True" AutoGenerateColumns="False"
  2.                         CellPadding="4" DataKeyNames="aID" DataSourceID="findlDataSource" ForeColor="#333333"
  3.                         GridLines="None" OnSelectedIndexChanged="afGridView_SelectedIndexChanged"
  4.                         PageSize="5" Visible="False" EnableViewState="False" OnPageIndexChanging="afGridView_PageIndexChanging">
  5.                         <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
  6.                         <Columns>
  7.                             <asp:CommandField SelectText="Update Account" ShowSelectButton="True">
  8.                                 <ControlStyle Font-Bold="True" ForeColor="Maroon" />
  9.                             </asp:CommandField>
  10.                             <asp:BoundField DataField="aID" HeaderText="aID" InsertVisible="False" ReadOnly="True"
  11.                                 SortExpression="aID" Visible="False" />
  12.                             <asp:BoundField DataField="Account No." HeaderText="Account No." SortExpression="Account No." />
  13.                             <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
  14.                             <asp:CheckBoxField DataField="Job No." HeaderText="Job No." SortExpression="Job No." />
  15.                         </Columns>
  16.                         <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
  17.                         <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
  18.                         <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
  19.                         <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
  20.                         <AlternatingRowStyle BackColor="White" />
  21.                     </asp:GridView>
  22.                     <asp:SqlDataSource ID="findlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnect %>"
  23.                         SelectCommand="FindAccount" SelectCommandType="StoredProcedure" EnableViewState="False">
  24.                         <SelectParameters>
  25.                             <asp:SessionParameter DefaultValue="" Name="all" SessionField="all" Type="String" />
  26.                             <asp:SessionParameter Name="AccountNo" SessionField="AccountNo" Type="Int64" />
  27.                             <asp:SessionParameter Name="description" SessionField="description" Type="String" />
  28.                             <asp:SessionParameter DefaultValue="" Name="jobno" SessionField="jobno" Type="String" />
  29.                         </SelectParameters>
  30.                     </asp:SqlDataSource>
  31.  
This is my c# code to handle the PageindexChanging

Expand|Select|Wrap|Line Numbers
  1. protected void afGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
  2.     {
  3.        afGridView.PageIndex = e.NewPageIndex;
  4.         afGridView.DataSource = findlDataSource;
  5.     }
  6.  
  7.  
Please Help
Mar 10 '08 #1
3 10610
Plater
7,872 Expert 4TB
You forgot to call the .DataBind() function in your page index changing function.
Mar 10 '08 #2
phpmel
69
If I say this
Expand|Select|Wrap|Line Numbers
  1. protected void afGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
  2.     {
  3.         afGridView.PageIndex = e.NewPageIndex;
  4.         afGridView.DataSource = findlDataSource;
  5.         afGridView.DataBind();
  6.  
  7.     }
it gives me the following error after i run the application

"Both DataSource and DataSourceID are defined on 'afGridView'. Remove one definition."........so that was why i left it out

Any other ideas
Mar 10 '08 #3
Plater
7,872 Expert 4TB
Hmm, then you should probably be doing this?
Expand|Select|Wrap|Line Numbers
  1. protected void afGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
  2. {
  3.    afGridView.PageIndex = e.NewPageIndex;
  4.    afGridView.DataBind();
  5. }
  6.  
Mar 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging...
6
by: Carlos Albert | last post by:
Hi everybody, I'm working with a gridview (4 bound columns and 1 template column, using databind from codebehind). It works just fine, but I tried to add paging, and when I click any paging...
5
by: yefei | last post by:
In my web design, I display records from a SQL DataBase according to some filters the GridView is defined with select commands and selest parameters however, I also want to display all records...
3
by: Marc Grutte | last post by:
Hi I am trying to bind a custom datasource to a gridview whilst paging is enabled. What is missing in this code to make the paging + binding work? thanks M <%@ Page Language="VB" %>
0
by: Don Miller | last post by:
Here is an example of what I believe is a bug in ASP.NET 2.0 GridView paging without postbacks (or at least not documented how to fix it). Once the GridView is displayed, clicking on any of the...
4
by: Don Miller | last post by:
This is a repost of a reproducible problem/bug with GridView with dynamic SQL and binding. Is there a better ASP.NET newsgroup I should post to where MS techs or MVPs take an interest in such...
1
by: Jason Huang | last post by:
Hi, In my C# 2.0 web form project, I have GridView1 in Form1.aspx. I am wondering why I can't find the PageIndexChanging event in the Form1.aspx.cs but the GridView1 still can go to other...
2
shek124
by: shek124 | last post by:
In my form, the gridview is bind , according to my selectedvalue in dropdownlist How can do paging in gridview using the pageindexchanging event for this condition.. please hwlp me
1
by: suganya | last post by:
I have displayed the data from the DB to the GridView made a column in the GridView as HyperLink allowed paging by setting the Allow Paging Property to "True". By clicking on the page no link I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.