Gridview; enabling paging programatically

Can't work out how to do this.

My code below displays the gridview correctly, but hundreds of records on one page. I figured I'd adjust the page size = 5 but no change...

So, I think I need to enable paging....how do I do this in the code?

Thx
Dim conn As New SqlConnection("Data Source=DAODEVBOX;Initial Catalog=suds_prototype;User ID=sa;Password=***")
 
        Dim ds As New Data.DataSet()
        Dim da As New SqlDataAdapter("select * from Centers", conn)
        da.Fill(ds, "Centres")
 
        grdDisplay.DataSource = ds.Tables("Centres")
        grdDisplay.DataBind()
        grdDisplay.Visible = True
        grdDisplay.PageSize = 5

Open in new window

bdb12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
you have to set the AllowPaging to true
you ahve to set the pagesize and the AllowPaging BEFORE you bind the grid



        Dim ds As New Data.DataSet()
        Dim da As New SqlDataAdapter("select * from Centers", conn)
        da.Fill(ds, "Centres")
 
        grdDisplay.AllowPaging=True
        grdDisplay.PageSize = 5 
        grdDisplay.DataSource = ds.Tables("Centres")
        grdDisplay.DataBind()
        grdDisplay.Visible = True

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bdb12Author Commented:
Ah, I didn't see that function...thx for the super fast response
0
bdb12Author Commented:
Hi Angel3, thx for your help with this.

I have another problem tho where the page numbers dont work when clicked, I started a new question here

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23125416.html

Any chance you can check it out?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.