Setting GridView PageSize at runtime

A

Adam Sandler

Hello,

Using VWD 2005 here and I want to set the GridView PageSize at runtime.
This URL has an example of what I exactly want to do...
http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.gridview.pagesize.aspx

Public Overridable Property PageSize As Integer

Dim instance As GridView
Dim value As Integer

value = instance.PageSize

instance.PageSize = value

Where I'm stuck is where does this code go? In what method to I put
this code into? I tried using GridView1.Load and it didn't work.

Any assitance is greatly appreciated... thanks!
 
A

Adam Sandler

Winista said:
You can put this code in Page_Load of your page.

Actually, I cannot... Public Overridable Property PageSize() As Integer
is a declaration... I get an error if I put a declaration inside an
event handler body.

VWD 2005 will create this stub for me:

Public Overridable Property PageSize() As Integer
Get

End Get
Set(ByVal value As Integer)

End Set
End Property

But that's where I get really confused... how does the code know which
PageSize I'm talking about? There could be more than 1 Gridview on a
page. Using e. and Me. doesn't help me out with scope issues.
 
J

Jeff Dillon

grdMyGrid.PageSize = 10

Adam Sandler said:
Actually, I cannot... Public Overridable Property PageSize() As Integer
is a declaration... I get an error if I put a declaration inside an
event handler body.

VWD 2005 will create this stub for me:

Public Overridable Property PageSize() As Integer
Get

End Get
Set(ByVal value As Integer)

End Set
End Property

But that's where I get really confused... how does the code know which
PageSize I'm talking about? There could be more than 1 Gridview on a
page. Using e. and Me. doesn't help me out with scope issues.
 
A

Adam Sandler

All... thanks for your help. I'm not sure if any code smells exist
here but this works:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim iPageSize As Integer
Dim myGridView As GridView
Dim ta As New DataSet1TableAdapters.T_ORDERSTableAdapter

myGridView = Me.GridView1
iPageSize = ta.GetData.Select.Length

myGridView.PageSize = iPageSize
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top