473,546 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView And PageIndexChangi ng

69 New Member
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 PageindexChangi ng

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 10626
Plater
7,872 Recognized Expert Expert
You forgot to call the .DataBind() function in your page index changing function.
Mar 10 '08 #2
phpmel
69 New Member
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 Recognized Expert Expert
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
16327
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 feature will not work. When I try to use paging I get this error: The GridView 'gvResults' fired event PageIndexChanging which wasn't handled.
6
6499
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 button (next, last, or page #), it return this error and I don't know what's wrong: Source Error: An unhandled exception was generated during the...
5
3369
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 in the database when the user press a "View All" button. In this case, I need to change the select comand and clear the parameters. And I did...
3
2182
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
1995
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 paging tools causes the GridView to completely disappear! This happens when either DataSets or DataTables are used (it doesn't work at all for...
4
2716
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 problems? Thanks. 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...
1
9947
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 pages. So, where exactly does the C# 2.0 web handle the PageIndexChanging thing? Thanks for help.
2
2785
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
2036
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 to view other records. For that I have given the coding as protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs...
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7698
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.