?
Solved

how to implement paging in gridview

Posted on 2007-07-26
18
Medium Priority
?
1,241 Views
Last Modified: 2008-01-09
hi
can anyone help me know how to implement paging in gridview.
i need to allowpaging in grid in apsx and then ref to the pageindexchanged event but do we write in that?

0
Comment
Question by:samir25
  • 9
  • 6
  • 2
  • +1
18 Comments
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19580626
Set allowpaging  property of GridView set to true!!

then map Event PageIndexChanging

  protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;

        GridView1.DataSource = ""
   
        GridView1.DataBind()
    }

Regards
Renju
0
 
LVL 7

Expert Comment

by:skiltz
ID: 19580628
<asp:gridview ID="gvTest" AllowPaging="true" runat="server"></asp:gridview>


 Protected Sub gvTest_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvTest.PageIndexChanged

    End Sub
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19580629
You can have pagersettings and PageSize Properties to set PagerSEttings and number of records in a page

Regards
Renju
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:samir25
ID: 19580637
I HAVE THIS IN 2005
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged
        gridview1.PageIndex=
    End Sub

which doesnt give me e.newpageindex
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19580649
the event is

GridView1_PageIndexChanging not PageIndexChanged

Yes , e.NewPageIndex

Regards
Renju


0
 
LVL 1

Author Comment

by:samir25
ID: 19580712
one more thing
GridView1.PageIndex = e.NewPageIndex
        GridView1.DataSource = dt
        GridView1.DataBind()

the datasource that i have is dt... so i shoudl create this as a public var?
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19580715
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanging

GridView1.PageIndex = e.NewPageIndex

GridView1.DataSource = ""
   
GridView1.DataBind()
End Sub

Regards
Renju

0
 
LVL 1

Author Comment

by:samir25
ID: 19580811
my paging is not working

The data source does not support server-side data paging.
Line 56:         GridView1.PageIndex = e.NewPageIndex
Line 57:         GridView1.DataSource = ""
Line 58:         GridView1.DataBind()
Line 59:     End Sub
Line 60:

i get error at line 58
how can the datasource be empty
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19580877
GridView1.DataSource = "" ' YOU Should specify your data source here

like

GridView1.DataSource = dt

Regards
Renju

0
 
LVL 1

Author Comment

by:samir25
ID: 19580878
thats what i asked u ealier ..

one more thing
GridView1.PageIndex = e.NewPageIndex
        GridView1.DataSource = dt
        GridView1.DataBind()

the datasource that i have is dt... so i shoudl create this as a public var?

guess i need to define dt as a public va
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19580882
dt is the datatable or dataset object you should obtain in PageLoad?
0
 
LVL 1

Author Comment

by:samir25
ID: 19580916
this is not the code to implement paging...i remem we do something ++ or -- ... to go to next page..here we are not at all doing that.
i had to make dt as public.
when i click to 2 i dont see any data
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19580937
inside your class
Dim objDs AS DataSet



inside Page_Load
{
da.Fill(objDs )

GridView1.DataSource = objDs.Tables[0];

GridView1.DataBind();
}


inside GridView1_PageIndexChanging
{
 GridView1.PageIndex = e.NewPageIndex;

GridView1.DataSource = objDs.Tables[0];

GridView1.DataBind();
}

Regards
Renju
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19580940
inside Page_Load
{
objDs = New DataSet()

da.Fill(objDs )

GridView1.DataSource = objDs.Tables[0];

GridView1.DataBind();
}
0
 
LVL 10

Expert Comment

by:SystemExpert
ID: 19580964
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.GridPageIndexChanged);
//Implement the EventHandler
private void GridPageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
//Bind the DataGrid again with the Data Source
DataGrid1.DataSource = dataSet1;
DataGrid1.DataBind();
}
0
 
LVL 1

Author Comment

by:samir25
ID: 19580965
here is what i am doing
Dim da As New OracleDataAdapter(FCommand)
da.Fill(dt) //after opening con
---
  GridView1.DataSource = dt
            GridView1.DataBind()

any inputs?
0
 
LVL 10

Expert Comment

by:SystemExpert
ID: 19580967
make sure

AllowCustomPaging="False"
0
 
LVL 12

Accepted Solution

by:
renjurdevan earned 2000 total points
ID: 19580992
Yes you are right!!

inside your class
Dim dt AS DataSet

inside Page_Load
{
dt = New DataSet()
Dim da As New OracleDataAdapter(FCommand)
da.Fill(dt) //after opening con

GridView1.DataSource = dt.Tables(0)
GridView1.DataBind()
}


inside GridView1_PageIndexChanging
{
 GridView1.PageIndex = e.NewPageIndex
GridView1.DataSource = dt.Tables(0)
GridView1.DataBind()
}


Regards
Renju
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question