Click here to Skip to main content
15,885,951 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello again programmers. I still dont get it in regards to paging. As you see I am binding pictures, hyperlinks ets to gridview and so far it works(In gridview itself). My problem is that i set may paging to true but it doesnt use it function. I doesnt have error so i dont know what the problem is plss help
My code on client side
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Buy.aspx.vb" Inherits="Buy" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br>
     <div style="overflow: auto; width: 776px; height: 712px">
        <asp:GridView ID="GridView1" runat="server" Width="766px" AutoGenerateColumns="False" AllowPaging="true" Height="708px" PageIndex="10"  OnPageIndexChanging = "GridView1_OnPageIndexChanging" >
    <columns>
              <asp:BoundField DataField="imageID" HeaderText="imageID"
              InsertVisible="False" ReadOnly="True"                               
              SortExpression="imageID" />
           
               <asp:HyperLinkField 
            DataTextField="ImageTitle" 
                    HeaderText="Title" 
                    SortExpression="ImageTitle" 
                    DataNavigateUrlFields="ImageTitle" 
                    DataNavigateUrlFormatString="ProductDetails.aspx?ProductID={0}" />

               
              <asp:TemplateField HeaderText="Image">
              <itemtemplate>
              <asp:Image ID="Image1" runat="server" Width ="75px" Height= "75px"          
              ImageUrl='<%# Eval("imageID", "ImageHandler.ashx?imageID={0}")%>'/>
              </itemtemplate>
              
              
              
              </columns>
              
    
    </div>

</br>

My code on Server Side
VB
Imports System.Data
Imports System.Data.SqlClient
Partial Class Buy
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            GridView1.PageIndex = 10
            bind()
        End If

    End Sub
    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, _
        ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        bind()
    End Sub

    Private Function getTable() As DataTable
        Dim conn As New SqlConnection("Data Source=ML0003135586\SQLEXPRESS;Initial Catalog=ecom;Integrated Security=True")
        Dim adap As New SqlDataAdapter("SELECT Image,ImageTitle,imageID from [tblSelling] ORDER BY [imageID] DESC", conn)
        Dim dt As New DataTable()
        adap.Fill(dt)
        Return dt
    End Function
    Private Sub bind()
        Dim dr As DataTable = getTable()
        GridView1.DataSource = dr
        GridView1.DataBind()
    End Sub
End Class

My paging does not work. Pls help.

thanks in advance and more power sirs
Posted
Updated 16-Aug-11 19:13pm
v2

Hi digimanus,


No need of setting page size, its already have defaulte value. If you can displaying more than 10 contents, wants to change

and write the code in gridview page indexchanging

C#
protected void gvReminder_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
        try
       {
           gvReminder.PageIndex = e.NewPageIndex;
           GridFillReminderDetails();
       }
        catch
        {
        }

   }


if you help this answer, dont forget to mark as accept answer
 
Share this answer
 
v2
Comments
Herman<T>.Instance 17-Aug-11 1:15am    
he uses bind()
Ashika s 17-Aug-11 1:18am    
same as bind(), i just change the name of function only:)
janwel 17-Aug-11 1:21am    
sir sorry but i dont know how to use c ^_^ thanks anyway
You dint specify the Event in Grid Tag

C#
<asp:gridview id="GridView1" runat="server" width="766px" autogeneratecolumns="False" allowpaging="true" height="708px" onpageindexchanging="GridView1_PageIndexChanging">


Specify this in your grid tag onpageindexchanging="GridView1_PageIndexChanging"

Hope this helps!
 
Share this answer
 
v2
in aspx GridView add:
- set PageSize property like PageSize="10"
- set OnPageIndexChanging="GridView1_PageIndexChanging" --> this is an event
 
Share this answer
 
v2
Comments
janwel 17-Aug-11 1:04am    
sir is it on the client side?
Herman<T>.Instance 17-Aug-11 1:12am    
no on server side because your data comes from server side. But your GridView component needs to know which event is used for paging
janwel 17-Aug-11 1:12am    
sir it isnt working ive updated my codes on what you just have said but still not working
Herman<T>.Instance 17-Aug-11 1:13am    
Like this:

<asp:GridView ID="GridView1" runat="server" Width="766px" AutoGenerateColumns="False" AllowPaging="true" Height="708px" PageSize="10" OnPageIndexChanging="GridView1_PageIndexChanging">
janwel 17-Aug-11 1:20am    
Sir i just want that whe i load the page it will be on page 1 of the gridview is it possible?
It might be hapening because your Gridview records may be less than 10,by default Gridview page size is 10,set pagesize to 5 or 2 then check it
 
Share this answer
 
Comments
janwel 17-Aug-11 1:17am    
Thanks sir it works but sir i have a question. Why is it posting on page 2 where the data was 1 to 5. i just want to hava a gridview that should be the first row(up) will be the last data of my database
janwel 17-Aug-11 1:20am    
Sir i just want that whe i load the page it will be on page 1 of the gridview is it possible?
Syed Salman Raza Zaidi 17-Aug-11 9:00am    
set page size of Gridview to 1

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