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.dt d">
<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 PersonCollectio n : 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(ite m)
End Sub
End Class
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles
Me.Load
If Not IsPostBack Then
GridView2.DataS ource = bron()
GridView2.DataB ind()
End If
End Sub
Protected Function bron() As PersonCollectio n
Dim objPersonCollec tion As New PersonCollectio n
For a As Integer = 0 To 3
Dim objPerson As New person
objPerson.Name = "Name" + a.ToString
objPersonCollec tion.add(objPer son)
Next
Return objPersonCollec tion
End Function
Protected Sub GridView2_PageI ndexChanging(By Val sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewPageEventAr gs) Handles
GridView2.PageI ndexChanging
End Sub
Protected Sub GridView2_PageI ndexChanged(ByV al sender As Object, ByVal e As
System.EventArg s) Handles GridView2.PageI ndexChanged
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="Tr ue" PageSize="2"
AutoGenerateCol umns="False">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:RadioButto nList ID="rblCategori es" 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:RadioButton List></ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html> 3 2184
Marc,
When you bind the GridView to a datasource that is not a DataSourceContr ol
(something other than SqlDataSource, ObjectDataSourc e, 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 PageIndexChangi ng handler to:
Protected Sub GridView2_PageI ndexChanging(By Val sender As Object, ByVal
e As System.Web.UI.W ebControls.Grid ViewPageEventAr gs) Handles
GridView2.PageI ndexChanging
Me.GridView2.Pa geIndex = e.NewPageIndex
GridView2.DataS ource = bron()
GridView2.DataB ind()
End Sub
If handling the events manually is a problem then you might take a look at
using an ObjectDataSourc e 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.dt d">
<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 PersonCollectio n : 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(ite m)
End Sub
End Class
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles
Me.Load
If Not IsPostBack Then
GridView2.DataS ource = bron()
GridView2.DataB ind()
End If
End Sub
Protected Function bron() As PersonCollectio n
Dim objPersonCollec tion As New PersonCollectio n
For a As Integer = 0 To 3
Dim objPerson As New person
objPerson.Name = "Name" + a.ToString
objPersonCollec tion.add(objPer son)
Next
Return objPersonCollec tion
End Function
Protected Sub GridView2_PageI ndexChanging(By Val sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewPageEventAr gs) Handles
GridView2.PageI ndexChanging
End Sub
Protected Sub GridView2_PageI ndexChanged(ByV al sender As Object, ByVal e As
System.EventArg s) Handles GridView2.PageI ndexChanged
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="Tr ue" PageSize="2"
AutoGenerateCol umns="False">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:RadioButto nList ID="rblCategori es" 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:RadioButton List></ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
thanks Jason!
"Jason Vermillion" wrote:
Marc,
When you bind the GridView to a datasource that is not a DataSourceContr ol
(something other than SqlDataSource, ObjectDataSourc e, 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 PageIndexChangi ng handler to:
Protected Sub GridView2_PageI ndexChanging(By Val sender As Object, ByVal
e As System.Web.UI.W ebControls.Grid ViewPageEventAr gs) Handles
GridView2.PageI ndexChanging
Me.GridView2.Pa geIndex = e.NewPageIndex
GridView2.DataS ource = bron()
GridView2.DataB ind()
End Sub
If handling the events manually is a problem then you might take a look at
using an ObjectDataSourc e 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.dt d">
<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 PersonCollectio n : 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(ite m)
End Sub
End Class
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles
Me.Load
If Not IsPostBack Then
GridView2.DataS ource = bron()
GridView2.DataB ind()
End If
End Sub
Protected Function bron() As PersonCollectio n
Dim objPersonCollec tion As New PersonCollectio n
For a As Integer = 0 To 3
Dim objPerson As New person
objPerson.Name = "Name" + a.ToString
objPersonCollec tion.add(objPer son)
Next
Return objPersonCollec tion
End Function
Protected Sub GridView2_PageI ndexChanging(By Val sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewPageEventAr gs) Handles
GridView2.PageI ndexChanging
End Sub
Protected Sub GridView2_PageI ndexChanged(ByV al sender As Object, ByVal e As
System.EventArg s) Handles GridView2.PageI ndexChanged
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="Tr ue" PageSize="2"
AutoGenerateCol umns="False">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:RadioButto nList ID="rblCategori es" 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:RadioButton List></ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
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 DataSourceContr ol
(something other than SqlDataSource, ObjectDataSourc e, 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 PageIndexChangi ng handler to:
Protected Sub GridView2_PageI ndexChanging(By Val sender As Object, ByVal
e As System.Web.UI.W ebControls.Grid ViewPageEventAr gs) Handles
GridView2.PageI ndexChanging
Me.GridView2.Pa geIndex = e.NewPageIndex
GridView2.DataS ource = bron()
GridView2.DataB ind()
End Sub
If handling the events manually is a problem then you might take a look at
using an ObjectDataSourc e 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.dt d">
>
<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 PersonCollectio n : 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(ite m)
>
End Sub
>
End Class
>
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles
Me.Load
>
If Not IsPostBack Then
>
GridView2.DataS ource = bron()
>
GridView2.DataB ind()
>
End If
>
>
End Sub
>
Protected Function bron() As PersonCollectio n
>
Dim objPersonCollec tion As New PersonCollectio n
>
For a As Integer = 0 To 3
>
Dim objPerson As New person
>
objPerson.Name = "Name" + a.ToString
>
objPersonCollec tion.add(objPer son)
>
Next
>
Return objPersonCollec tion
>
End Function
>
Protected Sub GridView2_PageI ndexChanging(By Val sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewPageEventAr gs) Handles
GridView2.PageI ndexChanging
>
>
>
>
>
End Sub
>
Protected Sub GridView2_PageI ndexChanged(ByV al sender As Object, ByVal e As
System.EventArg s) Handles GridView2.PageI ndexChanged
>
>
>
>
>
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="Tr ue" PageSize="2"
AutoGenerateCol umns="False">
>
<Columns>
>
<asp:TemplateFi eld>
>
<ItemTemplate >
>
<asp:RadioButto nList ID="rblCategori es" 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:RadioButton List></ItemTemplate>
>
</asp:TemplateFie ld>
>
</Columns>
>
</asp:GridView>
>
</div>
>
</form>
>
</body>
>
</html>
>
>
>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 not the
whole page, but a portion of the page.
Strangely enough the URL below
http://beta.asp.net/QUICKSTARTV20/aspnet/doc/ctrlref/data/gridview.aspx
(VB GridView Paging and Sorting Callbacks example)
|
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 feature will not work.
When I try to use paging I get this error:
The GridView 'gvResults' fired event PageIndexChanging which wasn't handled.
|
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 records and you only want 20
records displayed, does it read all 10000 and display 20 or does it
only read what it needs (Read 20 and display 20)?
Thanks
MA
|
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 when I page the
GridView (the paging controllers are in the gridview's footer). The
webpage doesnt scroll back to the top of the page, so when paging
through the GridView the user is always looking at the last 4-5 items
on the page. My current...
|
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 fields to be included in the
table, which is to be bound to the gridview.
The web form looks like so (Don't worry about the stupidity of this
web form for now.):
| |
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 paging tools causes the
GridView to completely disappear! This happens when either DataSets or
DataTables are used (it doesn't work at all for DataReaders because they
don't support paging apparently).
If you remove the...
|
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 coming to the client, right? I mean, the
paging feature isn't somehow making calls to the database for 25 records at
a time or anything like that is it?
I remember in the past having to write nasty stored procedures that took in
|
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 I do that?
I got an error msg that datareader does not allow paging in gridview....
because I use datareader in binding my data.
How can I convert my datareader to datatable using VB script so that I can allow paging to my Gridview?
I'm Using...
|
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 expression and allowing the GridView to
perform the sorting and paging.
How do people feel about each option for
(1) simple sorts (alphabetical, compound alphabetical)
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |