473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 2167
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.