472,986 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

paging with gridview

Hi

I am trying to bind a custom datasource to a gridview whilst paging is
enabled. What is missing in this code to make the paging + binding work?

thanks

M

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Public Class person

Dim _name As String

Public Property Name()

Get

Return _name

End Get

Set(ByVal value)

_name = value

End Set

End Property

End Class

Public Class PersonCollection : Inherits CollectionBase

Sub New()

MyBase.New()

End Sub

Public Property item(ByVal i As Integer)

Get

Return Me.List(i)

End Get

Set(ByVal value)

Me.List(i) = value

End Set

End Property

Public Sub add(ByVal item As person)

Me.List.Add(item)

End Sub

End Class

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load

If Not IsPostBack Then

GridView2.DataSource = bron()

GridView2.DataBind()

End If
End Sub

Protected Function bron() As PersonCollection

Dim objPersonCollection As New PersonCollection

For a As Integer = 0 To 3

Dim objPerson As New person

objPerson.Name = "Name" + a.ToString

objPersonCollection.add(objPerson)

Next

Return objPersonCollection

End Function

Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView2.PageIndexChanging

End Sub

Protected Sub GridView2_PageIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GridView2.PageIndexChanged

End Sub



</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:GridView ID="GridView2" runat="server" AllowPaging="True" PageSize="2"
AutoGenerateColumns="False">

<Columns>

<asp:TemplateField>

<ItemTemplate>

<asp:RadioButtonList ID="rblCategories" SelectedValue="<%#Bind('Name') %>"
runat="server">

<asp:ListItem Text="John" Value="Name0"></asp:ListItem>

<asp:ListItem Text="Nick" Value="Name1"></asp:ListItem>

<asp:ListItem Text="Bob" Value="Name2"></asp:ListItem>

<asp:ListItem Text="Ed" Value="Name3"></asp:ListItem>

</asp:RadioButtonList></ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

</div>

</form>

</body>

</html>
Jan 28 '07 #1
3 2140
Marc,

When you bind the GridView to a datasource that is not a DataSourceControl
(something other than SqlDataSource, ObjectDataSource, etc.) then you lose
some of the automatic functionality like paging and sorting.

You can bind the GridView to a class that implements ICollection but then
you'll have to handle some of the plumbing yourself.

Try modifying your PageIndexChanging handler to:

Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView2.PageIndexChanging
Me.GridView2.PageIndex = e.NewPageIndex
GridView2.DataSource = bron()
GridView2.DataBind()
End Sub

If handling the events manually is a problem then you might take a look at
using an ObjectDataSource to expose your collection.
http://webproject.scottgu.com/CSharp/Data/Data.aspx

This one has some good details about handling sorting
http://msdn2.microsoft.com/en-us/library/aa479347.aspx

hope this helps,
Jason Vermillion

"Marc Grutte" wrote:
Hi

I am trying to bind a custom datasource to a gridview whilst paging is
enabled. What is missing in this code to make the paging + binding work?

thanks

M

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Public Class person

Dim _name As String

Public Property Name()

Get

Return _name

End Get

Set(ByVal value)

_name = value

End Set

End Property

End Class

Public Class PersonCollection : Inherits CollectionBase

Sub New()

MyBase.New()

End Sub

Public Property item(ByVal i As Integer)

Get

Return Me.List(i)

End Get

Set(ByVal value)

Me.List(i) = value

End Set

End Property

Public Sub add(ByVal item As person)

Me.List.Add(item)

End Sub

End Class

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load

If Not IsPostBack Then

GridView2.DataSource = bron()

GridView2.DataBind()

End If
End Sub

Protected Function bron() As PersonCollection

Dim objPersonCollection As New PersonCollection

For a As Integer = 0 To 3

Dim objPerson As New person

objPerson.Name = "Name" + a.ToString

objPersonCollection.add(objPerson)

Next

Return objPersonCollection

End Function

Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView2.PageIndexChanging

End Sub

Protected Sub GridView2_PageIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GridView2.PageIndexChanged

End Sub



</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:GridView ID="GridView2" runat="server" AllowPaging="True" PageSize="2"
AutoGenerateColumns="False">

<Columns>

<asp:TemplateField>

<ItemTemplate>

<asp:RadioButtonList ID="rblCategories" SelectedValue="<%#Bind('Name') %>"
runat="server">

<asp:ListItem Text="John" Value="Name0"></asp:ListItem>

<asp:ListItem Text="Nick" Value="Name1"></asp:ListItem>

<asp:ListItem Text="Bob" Value="Name2"></asp:ListItem>

<asp:ListItem Text="Ed" Value="Name3"></asp:ListItem>

</asp:RadioButtonList></ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

</div>

</form>

</body>

</html>
Jan 29 '07 #2
thanks Jason!

"Jason Vermillion" wrote:
Marc,

When you bind the GridView to a datasource that is not a DataSourceControl
(something other than SqlDataSource, ObjectDataSource, etc.) then you lose
some of the automatic functionality like paging and sorting.

You can bind the GridView to a class that implements ICollection but then
you'll have to handle some of the plumbing yourself.

Try modifying your PageIndexChanging handler to:

Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView2.PageIndexChanging
Me.GridView2.PageIndex = e.NewPageIndex
GridView2.DataSource = bron()
GridView2.DataBind()
End Sub

If handling the events manually is a problem then you might take a look at
using an ObjectDataSource to expose your collection.
http://webproject.scottgu.com/CSharp/Data/Data.aspx

This one has some good details about handling sorting
http://msdn2.microsoft.com/en-us/library/aa479347.aspx

hope this helps,
Jason Vermillion

"Marc Grutte" wrote:
Hi

I am trying to bind a custom datasource to a gridview whilst paging is
enabled. What is missing in this code to make the paging + binding work?

thanks

M

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Public Class person

Dim _name As String

Public Property Name()

Get

Return _name

End Get

Set(ByVal value)

_name = value

End Set

End Property

End Class

Public Class PersonCollection : Inherits CollectionBase

Sub New()

MyBase.New()

End Sub

Public Property item(ByVal i As Integer)

Get

Return Me.List(i)

End Get

Set(ByVal value)

Me.List(i) = value

End Set

End Property

Public Sub add(ByVal item As person)

Me.List.Add(item)

End Sub

End Class

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load

If Not IsPostBack Then

GridView2.DataSource = bron()

GridView2.DataBind()

End If
End Sub

Protected Function bron() As PersonCollection

Dim objPersonCollection As New PersonCollection

For a As Integer = 0 To 3

Dim objPerson As New person

objPerson.Name = "Name" + a.ToString

objPersonCollection.add(objPerson)

Next

Return objPersonCollection

End Function

Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView2.PageIndexChanging

End Sub

Protected Sub GridView2_PageIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GridView2.PageIndexChanged

End Sub



</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:GridView ID="GridView2" runat="server" AllowPaging="True" PageSize="2"
AutoGenerateColumns="False">

<Columns>

<asp:TemplateField>

<ItemTemplate>

<asp:RadioButtonList ID="rblCategories" SelectedValue="<%#Bind('Name') %>"
runat="server">

<asp:ListItem Text="John" Value="Name0"></asp:ListItem>

<asp:ListItem Text="Nick" Value="Name1"></asp:ListItem>

<asp:ListItem Text="Bob" Value="Name2"></asp:ListItem>

<asp:ListItem Text="Ed" Value="Name3"></asp:ListItem>

</asp:RadioButtonList></ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

</div>

</form>

</body>

</html>

Jan 29 '07 #3
No problem, glad to help.

Jason

"Bert" wrote:
thanks Jason!

"Jason Vermillion" wrote:
Marc,

When you bind the GridView to a datasource that is not a DataSourceControl
(something other than SqlDataSource, ObjectDataSource, etc.) then you lose
some of the automatic functionality like paging and sorting.

You can bind the GridView to a class that implements ICollection but then
you'll have to handle some of the plumbing yourself.

Try modifying your PageIndexChanging handler to:

Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView2.PageIndexChanging
Me.GridView2.PageIndex = e.NewPageIndex
GridView2.DataSource = bron()
GridView2.DataBind()
End Sub

If handling the events manually is a problem then you might take a look at
using an ObjectDataSource to expose your collection.
http://webproject.scottgu.com/CSharp/Data/Data.aspx

This one has some good details about handling sorting
http://msdn2.microsoft.com/en-us/library/aa479347.aspx

hope this helps,
Jason Vermillion

"Marc Grutte" wrote:
Hi
>
I am trying to bind a custom datasource to a gridview whilst paging is
enabled. What is missing in this code to make the paging + binding work?
>
thanks
>
M
>
<%@ Page Language="VB" %>
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
<script runat="server">
>
Public Class person
>
Dim _name As String
>
Public Property Name()
>
Get
>
Return _name
>
End Get
>
Set(ByVal value)
>
_name = value
>
End Set
>
End Property
>
>
>
>
>
End Class
>
Public Class PersonCollection : Inherits CollectionBase
>
Sub New()
>
MyBase.New()
>
End Sub
>
Public Property item(ByVal i As Integer)
>
Get
>
Return Me.List(i)
>
End Get
>
Set(ByVal value)
>
Me.List(i) = value
>
End Set
>
End Property
>
Public Sub add(ByVal item As person)
>
Me.List.Add(item)
>
End Sub
>
End Class
>
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
>
If Not IsPostBack Then
>
GridView2.DataSource = bron()
>
GridView2.DataBind()
>
End If
>
>
End Sub
>
Protected Function bron() As PersonCollection
>
Dim objPersonCollection As New PersonCollection
>
For a As Integer = 0 To 3
>
Dim objPerson As New person
>
objPerson.Name = "Name" + a.ToString
>
objPersonCollection.add(objPerson)
>
Next
>
Return objPersonCollection
>
End Function
>
Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView2.PageIndexChanging
>
>
>
>
>
End Sub
>
Protected Sub GridView2_PageIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GridView2.PageIndexChanged
>
>
>
>
>
End Sub
>
>
>
>
>
>
>
</script>
>
<html xmlns="http://www.w3.org/1999/xhtml">
>
<head id="Head1" runat="server">
>
<title></title>
>
</head>
>
<body>
>
<form id="form1" runat="server">
>
<div>
>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" PageSize="2"
AutoGenerateColumns="False">
>
<Columns>
>
<asp:TemplateField>
>
<ItemTemplate>
>
<asp:RadioButtonList ID="rblCategories" SelectedValue="<%#Bind('Name') %>"
runat="server">
>
<asp:ListItem Text="John" Value="Name0"></asp:ListItem>
>
<asp:ListItem Text="Nick" Value="Name1"></asp:ListItem>
>
<asp:ListItem Text="Bob" Value="Name2"></asp:ListItem>
>
<asp:ListItem Text="Ed" Value="Name3"></asp:ListItem>
>
</asp:RadioButtonList></ItemTemplate>
>
</asp:TemplateField>
>
</Columns>
>
</asp:GridView>
>
</div>
>
</form>
>
</body>
>
</html>
>
>
>
Jan 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
2
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging...
3
by: mazdotnet | last post by:
Hi everyone, I know when you enable paging in a datagrid the entire data is read but only the data that you want is displayed to the end user. Has this changed for Gridview? So if you have 10000...
1
by: davidjgonzalez | last post by:
I have a GridView that has paging enabled. Each item (as defined in an ItemTemplate) includes several controls which have operations i would like to Atlas-enable. Everything is working well except...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
0
by: Don Miller | last post by:
Here is an example of what I believe is a bug in ASP.NET 2.0 GridView paging without postbacks (or at least not documented how to fix it). Once the GridView is displayed, clicking on any of the...
3
by: Ronald S. Cook | last post by:
I was told that if calling lots of records from the database (let's say 100,000), that the GridView's paging feature would automatically "handle" everything. But the 100,000 records are still...
2
by: jaredciagar | last post by:
Hi Guys, Please Help ME.... I have a problem in displaying data in my gridview with paging, the data from the database is displaying to my gridview but I want to allow paging in my gridview.how can...
1
by: John A Grandy | last post by:
In regard to a GridView that must support searching, filtering, sorting, and paging ... There is a tradeoff in performing the sorting and paging in the database versus to creating a CLR sort...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.