Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a gridview in my page and 4 imagebuttons (First, Previous, Next, Last) which seems to don't work perfectly( when i click for example next imagebutton it shows me the message "no records was found")

this the begining tags o my gridview:
ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="UserID"
            AllowPaging="true" AllowSorting="true" EmptyDataText="No record was found" CellPadding="4"
            ForeColor="#333333" GridLines="None" PageSize="3">
            <PagerSettings Visible="false" />

and these are my imagebuttons
ASP.NET
<asp:Label ID="Label1" runat="server" BackColor="#FF8080" Text="Record Not Found"
Visible="False" Width="279px"></asp:Label>
<asp:ImageButton ID="ImageButton1" PostBackUrl="~/gridview.aspx" ImageUrl="~/images/ico_precedant.jpg"
OnClick="imgPageFirst_Command" runat="server" />
<asp:ImageButton ID="ImageButton2" PostBackUrl="~/gridview.aspx" ImageUrl="~/images/Arrow Left.bmp"
OnClick="imgPagePrevious_Command" runat="server" />
<asp:ImageButton ID="ImageButton3" PostBackUrl="~/gridview.aspx" ImageUrl="~/images/Arrow Right.bmp"
OnClick="imgPageNext_Command" runat="server" />
<asp:ImageButton ID="ImageButton4" PostBackUrl="~/gridview.aspx" ImageUrl="~/images/ico_suivant.jpg"
OnClick="imgPageLast_Command" runat="server" />

Note that my gridview and the imagebuttons are all inside an updatepanel
and these lines are the lines of my code behind
VB
Protected Sub imgPageFirst_Command(sender As Object, e As ImageClickEventArgs) Handles img_first.Click
       GridView1.PageIndex = 0
       GridView1.DataBind()
   End Sub
   Protected Sub imgPagePrevious_Command(sender As Object, e As ImageClickEventArgs) Handles img_previous.Click
       Dim i As Integer = GridView1.PageIndex - 1
       If GridView1.PageIndex <> 0 Then
           GridView1.PageIndex = i
       End If
       GridView1.DataBind()
   End Sub
   Protected Sub imgPageNext_Command(sender As Object, e As ImageClickEventArgs) Handles img_next.Click
       Dim i As Integer = GridView1.PageIndex + 1
       If GridView1.PageIndex < GridView1.PageCount Then
           GridView1.PageIndex = i
       End If
       GridView1.DataBind()
   End Sub
   Protected Sub imgPageLast_Command(sender As Object, e As ImageClickEventArgs) Handles img_last.Click
       GridView1.PageIndex = GridView1.PageCount
       GridView1.DataBind()
   End Sub
Posted
Updated 17-Jun-12 11:44am
v2
Comments
db7uk 17-Jun-12 17:44pm    
Updated by removing repeated content.

1 solution

two things.

1) when you databind the grid again you are not setting the datasource property again.

2) The purpose of the label control does not look right. why have the gridview property "EmptyDataText" set to the same(ish) text as the label??? Consider removing label if not used for anything. This maybe a label for the current page but this is not being updated in your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900