Thursday, March 29, 2012

Paging problem

I've created a Datagrid and the AllowPaging is set to True, PageSize is set to 3. My database have a total of 7 records. When I run my page, only 3 records are display due to the PageSize, as I have 7 records, it shows there are total 3 pages. When I click the 2 or 3, nothing happen and it is still on the first page as it should display the next page with another 3 records. Any idea on fixing this problem.

I'm using Webmatrix 1.1 and MS SQL server 2000.

Thanks in advance.If you're using the default code generated by the Web Matrix it should just work. A few things to check:
1. Are you using a dataset which is bound to the datagrid containing the data which should be displayed? The default paging mechanism only works fine with a dataset using the Web Matrix code.
2. Is there a DataGrid_Page event handler in your code? It should contain:


DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()

Check if the event is registered correctly to the PageIndexChanged event of the datagrid. It should point to the DataGrid_Page event method.
3. The Page_Load event should check for a postback of the page and only bind the data to the grid when there's NO postback:

Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
' Databind the data grid on the first request only
' (on postback, rebind only in paging command)
BindGrid()
End If
End Sub

Hope this can help you?

Tip: turn page tracing on (Trace = "True") to monitor which events are fired to determine where the problem is located in the code.
Thanks bdesmet, I've got it running now.

Paging Problem

Private Sub LoadData()
Dim keyword As String = Request.QueryString("kw")
Dim ds As New DataSet
ds = BusinessLayer.Usefull.FindBook(keyword.ToLower)

gv1.DataSource = ds.Tables(0)
gv1.DataBind()
End Sub
Protected Sub gv1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
gv2 = e.Row.FindControl("gv2")
gv2.DataSource = dtOutlines
gv2.DataBind()
End If
End Sub

Protected Sub gv2_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
CType(gv1.FindControl("gv2"), GridView).PageIndex = e.NewPageIndex
'Error Happens here, Object reference not set to an instance of an object
LoadData()
End Sub

HTML:
GV2:OnPageIndexChanging="gv2_PageIndexChanging"

Any Ideas??

Any Ideas??


Protected Sub gv2_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
ctype(sender,GridView).PageIndex=e.NewPageIndex
'Error Happens here, Object reference not set to an instance of an object
LoadData()
End Sub


Paging Problems

I have set up paging on a datagrid on a webform.
Everything loads up nicely but when I click on a page link nothing happens.
Any Ideas anyone??
Thanks in AdvanceYou have to implement your own procedure to implement the paging functionality. Have a look at 4guys:-

http://www.4guysfromrolla.com/webtech/072101-1.2.shtml

Paging question

Hello all:

Suppose I have a datagrid and when I retrieve a datatable, and flake a
dataview off of that table to bind to my grid, my datatable has, say,
10,000+ records in it.
Suppose further that my datagrid has paging turned on, and I display 10
rows of data at a time.
Let us further suppose that I am caching the table in the page cache,
and retrieving it at datagrid binding time:

myDataView = New DataView(CType(Cache.Item("myDataTable"),DataTable)
myDataGrid.DataSource = myDataView
myDataGrid.DataBind()

Given that my datagrid will display only 10 rows at a time -
1) How many rows are in my dataview? All of them, or just the 10 being
displayed in the datagrid?
2) Where in memory is my datatable - on the server, or on the client?

I'm trying to figure out if I have a bandwidth issue whether I allow
the grid to display all of the rows, or if I page it...

Thanks much,
zdrakec> Given that my datagrid will display only 10 rows at a time -
> 1) How many rows are in my dataview? All of them, or just the 10 being
> displayed in the datagrid?

DataViews don't "hold" any data at all, they are just filters of the
original data in your DataTable.

> 2) Where in memory is my datatable - on the server, or on the client?

All of your object instances are always held in memory on the server that
created them.

> I'm trying to figure out if I have a bandwidth issue whether I allow
> the grid to display all of the rows, or if I page it...

You may want to consider pulling down just 10 records from your database at
a time and make more trips to the data store than pulling down all of them
and not going back to the data store again.

> Thanks much,
> zdrakec
Hello Scott:

Ya know, I knew that about dataviews, so I must be getting senile :)

I'm wondering, not so much about holding that big a recordset on the
server memory, but how much of that data is actually being sent via my
network back to the client...all of it, or just the 10 records I have
my grid display at a time?

Thank you,
zdrakec
All of it is being sent to the client, regardless of how many records you
opt to show at any one time. This is why I suggest getting the records in
smaller batches and more often.

"zdrakec" <zdrakec@.yahoo.com> wrote in message
news:1121808311.966023.57210@.z14g2000cwz.googlegro ups.com...
> Hello Scott:
> Ya know, I knew that about dataviews, so I must be getting senile :)
> I'm wondering, not so much about holding that big a recordset on the
> server memory, but how much of that data is actually being sent via my
> network back to the client...all of it, or just the 10 records I have
> my grid display at a time?
> Thank you,
> zdrakec
That's what I figured, but I wasn't sure. Yes, I may well have to fetch
smaller batches...

Thanks for the info!

Cheers,
zdrakec

Paging query results...or however you say this

I got a table with thousands of news articles.
Need a query that return a certain number of articles, for a specific day, and then display only a certain number at a time.
On the page I guess I will have "Next, Previous, First, Last" links...

So I guess the query will go like "Give me all the articles for this day, from number X up to number "X + 20"

not sure how to start with this...any ideas welcome to push me offHMMM...seems it might not be so hard. by setting the rowcount, i can limit the number of records returned by the query...but how to I say "start at row number x" ?

SET rowcount 10
SELECT ArticleID, Title
FROM tblArticles
WHERE PublishDate = '2004-06-02 00:00:00.000' and lang = 1
SET ROWCOUNT 0
this seems to work fine...any critic?
-- the "starting values". In our case, we need two:
DECLARE @.startingID INT;
-- returns resutls from row @.a to row @.b:
DECLARE @.a INT;
DECLARE @.b INT;
SET @.a = 1 -- start at row 2
SET @.b = 100 -- end at row 5
-- get the starting date and starting ID to return results:
SET rowcount @.a
SELECT @.startingID = ArticleID
FROM tblArticles
WHERE PublishDate = '2004-06-04 00:00:00.000' and lang = 1
ORDER BY ArticleID ASC
-- find out how many rows to return, and set the rowcount:
SET @.b = 1 + @.b - @.a
SET rowcount @.b
-- now return the results:
SELECT * FROM tblArticles
WHERE
PublishDate = '2004-06-04 00:00:00.000' AND lang = 1 AND ArticleID >= @.StartingID
ORDER BY PublishDate ASC,ArticleID ASC
-- clean up:
SET rowcount 0 let me convert this to a sproc
now for the page itself.
hmmm...must know before hand how many articles...guess another query needed
how to keep track of what page we are at, and so on, without running this query again and again (database design bad..not done by me..not very optimized)

Paging Query

I have created some code with some help from this forum and it nearlly works the way I want it to !!

My original code would display the results of a search without any paging...

so i got the help on customizing the code to include paging of the results.

Before I added the paging code, when you loaded my search web page no results would show until you entered some search criteria.
when i got the paging code working the web page when initially loaded would display all the records and would page OK and when you entered some search criteria, it would filter the relevant results.
I then stumbled on how to modify this code to do what I want and it works but only for a while then it errors out on both my local and server copy. To get it working I have to run the aspx page that shows all the results, then when I run my modified page it works again ?
There must be some sort of caching going on, but im not sure??

I will include the code below from my two files, the only difference in the code is the lines I post...the 1st bit of code is the file that displays all the rows of data when loaded and pages fine


<%@dotnet.itags.org. Page Explicit="True" Language="VB" Debug="True" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@dotnet.itags.org. Register TagPrefix="ASPFD" TagName="Header" src="http://pics.10026.com/?src=header.ascx" %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.OleDb" %>
<script runat="server"
' Sub Page_Load(Sender As Object, E As EventArgs)
' Header.AddPageName("Search")
' End Sub

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

If Not Page.IsPostBack Then

Session("SelectStatement") = "Select * From GolfersQ Order By Lastname"
BindGrid()

End If

End Sub

Sub Search_Click(ByVal Sender As Object, ByVal E As EventArgs)

Dim SelectStatement As String
Dim WhereClause As String

Message.Text = ""

' If they only entered a Lastname, go to the Lastname page


The next snippet of code is from my search page, that works fine, even paging for a while but then suddenly starts erroring out, until I run the original page again, you will see the lines of code i have commented out..

<script runat="server"
Sub Page_Load(Sender As Object, E As EventArgs)
Header.AddPageName("Search")
End Sub

' Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' If Not Page.IsPostBack Then

' Session("SelectStatement") = "Select * From GolfersQ Order By Lastname"
' BindGrid()

' End If

' End Sub

Sub Search_Click(ByVal Sender As Object, ByVal E As EventArgs)

Dim SelectStatement As String
Dim WhereClause As String

Message.Text = ""

' If they only entered a Lastname, go to the Lastname page


I know this sounds confusing, its difficult to explain whats going on, but if anybody can point me in the right direction on whats happening, I would be very grateful.
Thanks in advance
SteveIt would probably help if you showed us the error message.
Hi,
Here is the error message im getting

Server Error in '/' Application.
------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 110:
Line 111: Connect.ConnectionString = ConnectString
Line 112: Adapter.SelectCommand = New OleDbCommand(Session("SelectStatement").ToString(), Connect)
Line 113: 'Adapter.SelectCommand.Connection.Open()
Line 114: Adapter.Fill(Top100DS, "GolfersQ")

Source File: D:\Webspace\golfinmanchester.co.uk\wwwroot\search.aspx Line: 112

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
ASP.Search_aspx.BindGrid() in D:\Webspace\golfinmanchester.co.uk\wwwroot\search.aspx:112
ASP.Search_aspx.AdsGrid_Page(Object sender, DataGridPageChangedEventArgs e) in D:\Webspace\golfinmanchester.co.uk\wwwroot\search.aspx:126
System.Web.UI.WebControls.DataGrid.OnPageIndexChanged(DataGridPageChangedEventArgs e) +110
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +349
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +100
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +120
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1277

------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

hope this helps you help me !!
Session("SelectStatement") is probably null (Nothing).

Paging Records on at a time.

Hello,
I have an asp.net application that will use a SQL Server DBMS for the
backend.
On my asp.net form. I have a next, previous, last and first buttons on my
form.
Basically, this application will allow the user to page through some data
one record at a time.
Let's say my SQL statement returns the following rows with ID's of (1, 3,
5, 9, 10).
What would be the best way that I can always retrieve the previousID and
nextID according to the rows my Select SQL statement returned?
Thanks,
MarkIf your using a DataGrid, you can use the Inbuilt paging.
This will keep track of what the previous and next items are.
private void dg_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dg.CurrentPageIndex = e.NewPageIndex;
PopulateGrid(); //this would rebind the grid but the the CurrentPageIndex
set as above
}
Also ensure to set the AllowPaging attribute on your DataGrid to true,
and in your case, set the PageSize to 1
If your using a DataList, i don't believe it has InBuilt paging, and you'll
have to build a custom solution
"SouthSpawn" <southspawn@.aol.com> wrote in message
news:45aab3325cec912c9cb54249ee98a80d@.lo
calhost.talkaboutsoftware.com...
> Hello,
> I have an asp.net application that will use a SQL Server DBMS for the
> backend.
> On my asp.net form. I have a next, previous, last and first buttons on my
> form.
> Basically, this application will allow the user to page through some data
> one record at a time.
> Let's say my SQL statement returns the following rows with ID's of (1, 3,
> 5, 9, 10).
> What would be the best way that I can always retrieve the previousID and
> nextID according to the rows my Select SQL statement returned?
> Thanks,
> Mark
>

Paging Records on at a time.

Hello,

I have an asp.net application that will use a SQL Server DBMS for the
backend.
On my asp.net form. I have a next, previous, last and first buttons on my
form.
Basically, this application will allow the user to page through some data
one record at a time.

Let's say my SQL statement returns the following rows with ID's of (1, 3,
5, 9, 10).
What would be the best way that I can always retrieve the previousID and
nextID according to the rows my Select SQL statement returned?

Thanks,
MarkIf your using a DataGrid, you can use the Inbuilt paging.
This will keep track of what the previous and next items are.

private void dg_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)

{

dg.CurrentPageIndex = e.NewPageIndex;

PopulateGrid(); //this would rebind the grid but the the CurrentPageIndex
set as above

}

Also ensure to set the AllowPaging attribute on your DataGrid to true,
and in your case, set the PageSize to 1

If your using a DataList, i don't believe it has InBuilt paging, and you'll
have to build a custom solution

"SouthSpawn" <southspawn@.aol.com> wrote in message
news:45aab3325cec912c9cb54249ee98a80d@.localhost.ta lkaboutsoftware.com...
> Hello,
> I have an asp.net application that will use a SQL Server DBMS for the
> backend.
> On my asp.net form. I have a next, previous, last and first buttons on my
> form.
> Basically, this application will allow the user to page through some data
> one record at a time.
> Let's say my SQL statement returns the following rows with ID's of (1, 3,
> 5, 9, 10).
> What would be the best way that I can always retrieve the previousID and
> nextID according to the rows my Select SQL statement returned?
> Thanks,
> Mark

paging records in ASP.NET using datareaders

Hi FriendsI am facing a problem. Plz help me to solve my problemThe scenario is as followsI have a ASP.NET page in which listing of records is done. Each record has 8 fields. the records are coming from the stored procedure where i am fetching data from 2 or more table. sometimes the data returned by the stored procedure doesn't have a unique or primary key.i am displaying records in the table (one record per row).also i am using the datareader i.e. connected environment.Now the problem is that, the listing page contains thousands of records after 3 or 4 days of operation at client side. I want to page the records (as done in the google.com). BUT the limitation is that i am not allowed to use DATAGRID, REPEATER, DATALISTand any such control. plus i am not allowed to do any drastic changes in my stored procedures also i am compelled to use datareaders.How can i achieve paging in such situationPlz help meThank You in advance

kamii47 wrote:

BUT the limitation is that i am not allowed to use DATAGRID, REPEATER, DATALISTand any such control. plus i am not allowed to do any drastic changes in my stored procedures also i am compelled to use datareaders. How can i achieve paging in such situation Plz help me Thank You in advance

Why you are compelled to not use these helpful control? Also maybe you need to chnage the stored procedure.

Any suggested change may cost you entire application rebuilding.

Check thishttp://www.dotnetjunkies.com/Article/975BE770-E5DC-4610-870B-A82BDB9B8845.dcik

regards

Paging sample in C#?

Hello folks,
Anyone have some Paging sample in c#?
All code sample I was found are uses javascript as link.
===================================
e.g. javascript:__doPostBack('_ctl1$_ctl0$Pager$_ctl6','')
===================================

But, I'm looking for a paging sample which uses "real link".
===================================
e.g. filename.asp?page=2
===================================

Can anyone help me?
Thank you in advance!!!Just some idea to get you started:

When using a datagrid you could retrieve the id with the Request.QueryString("page"). Assign this value (convert it to an integer first) to the datagrid.newpageindex.

Grz, Kris.

Paging Setup

When I turn on paging for a databound GridView I get the following options for navigation
NextPreviousNumericNextPreviousFirstLastNumericFirstLastHowever, I would like to show the NextPrevious and Numeric in much the same way as paging is presented by Google

PREVIOUS 1 2 3 4 5 6 (7) 8 9 10 11 12 NEXT

Is there a way I can do this?

Set the mode to "Numeric"

and then in the Grid's "RowCreated" event (actually there's multiple points you could catch doing this at), look to see if the type of Row is the Pager, and then you can add controls (in this case, you'd add link buttons or just plain old links with javascript that mimics what the stock pager links do)


Thanks MorningZ,

I'll give that a go :)

Paging the form

I have a registration page which is very long. I would like to cut it into 2-3 pages instead. I would like to know if there are any ways to cut the form without creating two extra pages for that?

Thank you

You could use the multiview or wizard control.

More info:
Multiview
Wizard


Another interesting one could come from the AJAX control toolkit:Tabs.

Grz, Kris.

paging text

I am trying to build a site using Visual Web Developer Express. I am using master pages and a TreeListMenu and a Breadcrumb for navigation. Is there a way to have a SSI in the ContentPlaceholder that will bring in the HTML code and page it. It will be a faily large amount of text and I want to spit it up into differnt pages dynamicly. Is there a way to do this without using XML. I tried that (using CDATA in the elements) and evidently I am doing something wrong because the data never showed up.

Just want to know if this is possible some other way or if I am making this harder than what it is.

Thanks for any help.

refer to

http://forums.asp.net/thread/1282548.aspx

Paging through a portion of a table in a DataGrid

Hi folks,

I am trying to page through a portion of the data in a table and therefore I
think I need to use Custom Paging.

... but, I am wondering if I can pass a dataset that was obtained through a
function that returns a dataset that is a portion of a table. Apparently I
cannot do this as I keep getting the CurrentPageIndex must be or = 0 and <
PageCount error.

I guess I do not fully understand Custom Paging yet, so I will do some
reading on it but it seems that my method should work. My only thought is
that the PageCount is based on ALL of the records in a table and not just the
subset of records returned from my function. Also, I have found that
PageCount is readonly.

Here is the code I am using:

Function GetRecords(ByVal record As Integer) As System.Data.DataSet

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole
DB Services=-4; Data Source=C:\path\accessfile.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "SELECT [tablename].* FROM [tablename] WHERE
([discussion].[record] = @dotnet.itags.org.anotherrecord)"
Dim dbCommand As System.Data.IDbCommand = New Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_record As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_record.ParameterName = "@dotnet.itags.org.record"
dbParam_record.Value = record
dbParam_record.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_record)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function

Sub BindData(sortExpr as String)

Dim dataSet As DataSet = New DataSet()

dataSet = GetRecord(recordID)

'Finally, specify the DataSource and call DataBind()
DataGrid1.DataSource = dataset
DataGrid1.DataBind()

End Sub

Any feedback is appreciated.
- GlennPaging in Dataset assumes that the dataset contains complete set of data.

-Augustin

"glenn" wrote:

Quote:

Originally Posted by

Hi folks,
>
I am trying to page through a portion of the data in a table and therefore I
think I need to use Custom Paging.
>
... but, I am wondering if I can pass a dataset that was obtained through a
function that returns a dataset that is a portion of a table. Apparently I
cannot do this as I keep getting the CurrentPageIndex must be or = 0 and <
PageCount error.
>
I guess I do not fully understand Custom Paging yet, so I will do some
reading on it but it seems that my method should work. My only thought is
that the PageCount is based on ALL of the records in a table and not just the
subset of records returned from my function. Also, I have found that
PageCount is readonly.
>
Here is the code I am using:
>
Function GetRecords(ByVal record As Integer) As System.Data.DataSet
>
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole
DB Services=-4; Data Source=C:\path\accessfile.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )
>
Dim queryString As String = "SELECT [tablename].* FROM [tablename] WHERE
([discussion].[record] = @.anotherrecord)"
Dim dbCommand As System.Data.IDbCommand = New Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
>
Dim dbParam_record As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_record.ParameterName = "@.record"
dbParam_record.Value = record
dbParam_record.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_record)
>
Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(dataSet)
>
Return dataSet
End Function
>
>
Sub BindData(sortExpr as String)
>
Dim dataSet As DataSet = New DataSet()
>
dataSet = GetRecord(recordID)
>
'Finally, specify the DataSource and call DataBind()
DataGrid1.DataSource = dataset
DataGrid1.DataBind()
>
End Sub
>
>
>
Any feedback is appreciated.
- Glenn

Paging through a datagrid

I have a datagrid that contains hundreds of items. I want to be able to sho
w
25 per page and then use the page numbers on the bottom of the datagrid so
that the user can scan through the pages to find the record they are looking
for.
However, when I click page 2, for instance, it doesn't do anything and the
same records show up to the user.
Any help on how I can solve this problem would be appreciated.
Regards
BrianPaging through a datagrid in ASP.NET 1.x requires writing customized code fo
r
the OnPageIndexChanged event. Refer to the Quickstart tutorials for a sampl
e:
http://samples.gotdotnet.com/quicks.../datagrid10.src
The MSDN has also another helpful article about those common DataGrid
mistakes:
http://msdn.microsoft.com/library/d...ridmistakes.asp
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"bbdobuddy" wrote:

> I have a datagrid that contains hundreds of items. I want to be able to s
how
> 25 per page and then use the page numbers on the bottom of the datagrid so
> that the user can scan through the pages to find the record they are looki
ng
> for.
> However, when I click page 2, for instance, it doesn't do anything and the
> same records show up to the user.
> Any help on how I can solve this problem would be appreciated.
> Regards
> Brian

Paging through a datagrid

I have a datagrid that contains hundreds of items. I want to be able to show
25 per page and then use the page numbers on the bottom of the datagrid so
that the user can scan through the pages to find the record they are looking
for.

However, when I click page 2, for instance, it doesn't do anything and the
same records show up to the user.

Any help on how I can solve this problem would be appreciated.

Regards
BrianPaging through a datagrid in ASP.NET 1.x requires writing customized code for
the OnPageIndexChanged event. Refer to the Quickstart tutorials for a sample
http://samples.gotdotnet.com/quicks.../datagrid10.src

The MSDN has also another helpful article about those common DataGrid
mistakes
http://msdn.microsoft.com/library/d...ridmistakes.asp

--
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

"bbdobuddy" wrote:

> I have a datagrid that contains hundreds of items. I want to be able to show
> 25 per page and then use the page numbers on the bottom of the datagrid so
> that the user can scan through the pages to find the record they are looking
> for.
> However, when I click page 2, for instance, it doesn't do anything and the
> same records show up to the user.
> Any help on how I can solve this problem would be appreciated.
> Regards
> Brian

Paging through the gridview

Error:System.NullReferenceException: Object reference not set to an instance of an object.

Hi! I get an error on this block:

protectedvoid gvSearch_SelectedIndexChanged(object sender,EventArgs e)

{

try

{

// This will contain the selectedValue of the row

string selectedCategory = gvSearch.SelectedRow.Cells[1].Text;

}

catch (Exception err)

{

lblError.Text = err.ToString();

}

}

I got the numbers showing at the bottom of the gridview, but when I click on a number i get this error. Thanks for the help!

To access SelectedRow in GridView you need to set enableSelection Property to True.

Paging with datagrid

Hi all,

I am looking for some pointers as to how to do paging with datagrid..
Well, there are so many samples out there.. What I am looking for is to
be able to have a dynamic query where the user can enter something in a
text box and search for that and we show the results using a paged
datagrid..

When the page is loaded, I want to execute a query like SELECT * FROM
AUTHORS WHERE AUTHOR_NAME = Request("AuthorName") or something like
that, rather than like all these examples that show quueries like
SELECT * FROM AUTHORS..

TIA,
AlaguCheck out this article,
http://www.microsoft.com/india/msdn...verControl.aspx

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"Alagu" <kolandtech@.gmail.com> wrote in message
news:1105430279.943396.21800@.f14g2000cwb.googlegro ups.com...
> Hi all,
> I am looking for some pointers as to how to do paging with datagrid..
> Well, there are so many samples out there.. What I am looking for is to
> be able to have a dynamic query where the user can enter something in a
> text box and search for that and we show the results using a paged
> datagrid..
> When the page is loaded, I want to execute a query like SELECT * FROM
> AUTHORS WHERE AUTHOR_NAME = Request("AuthorName") or something like
> that, rather than like all these examples that show quueries like
> SELECT * FROM AUTHORS..
> TIA,
> Alagu

Paging with a datarepeater

Adding a paging feature to data displayed in a data repeater is decidedly easy with the simple addition of a paged data source.

I couldn't find much information on this topic in this forum but I did find some decent C# code elsewhere that I translated to VB.Net. Since this forum has helped me more times than I can count I always like to post my solutions in case they some day help someone else.

Use this code in your page load and make sure you have a label called lblCurrentPage above your repeater and two hyperlinks called lnkPrev and lnkNext below your reader. You will also need a data adapter (mine is called sdaData here).

This code handles the rest.

If Not Me.Page.IsPostBack Then
Dim cn As New SqlClient.SqlConnection(Session("PropertyConnection"))
Dim cm As New SqlClient.SqlCommand("", cn)
Dim ds1 As New DataSet
Dim strPsn As String

sdaData.SelectCommand.Connection = cn
sdaData.SelectCommand.CommandText = "select * from [orders] where customer = '" & strWhatever & "' order by orderdate desc"
sdaData.Fill(ds1)

Dim objPds As New PagedDataSource
objPds.DataSource = ds1.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 5 'sets number of pages to display
Dim CurPage As Integer
If Len(Request("Page")) > 0 Then
CurPage = CInt(Request("Page"))
Else
CurPage = 1
End If
objPds.CurrentPageIndex = CurPage - 1
lblCurrentPage.Text = "Page: " & CurPage.ToString() & " of " & objPds.PageCount.ToString()

If Not (objPds.IsFirstPage) Then
lnkPrev.NavigateUrl = "mypage.aspx?page=" & CStr(CurPage - 1)
End If
If Not objPds.IsLastPage Then
lnkNext.NavigateUrl = "mypage.aspx?page=" & CStr(CurPage + 1)
End If

Repeater1.DataSource = objPds
Repeater1.DataBind()
End If

It should be very simple to do the same for a datalist.The best place for this kind of code is the code bank.

paging with datalist

I'm creating a dataset and populating a datalist from that. How can i page
the datalist? I want to see 15 records at time on my page so at the bottom I
want to see
1-15 of 100
nextNuB,
See if this article helps:
http://aspalliance.com/articleViewer.aspx?aId=157&pId=
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"NuB" <csharpcoder@.optonline.net> wrote in message
news:uxqhTq6tFHA.1132@.TK2MSFTNGP10.phx.gbl...
> I'm creating a dataset and populating a datalist from that. How can i page
> the datalist? I want to see 15 records at time on my page so at the bottom
> I want to see
> 1-15 of 100
> next
>
>

paging with datalist

I'm creating a dataset and populating a datalist from that. How can i page
the datalist? I want to see 15 records at time on my page so at the bottom I
want to see

1-15 of 100
nextNuB,

See if this article helps:

http://aspalliance.com/articleViewer.aspx?aId=157&pId=

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"NuB" <csharpcoder@.optonline.net> wrote in message
news:uxqhTq6tFHA.1132@.TK2MSFTNGP10.phx.gbl...
> I'm creating a dataset and populating a datalist from that. How can i page
> the datalist? I want to see 15 records at time on my page so at the bottom
> I want to see
> 1-15 of 100
> next

Paging with datagrid

Hi all,
I am looking for some pointers as to how to do paging with datagrid..
Well, there are so many samples out there.. What I am looking for is to
be able to have a dynamic query where the user can enter something in a
text box and search for that and we show the results using a paged
datagrid..
When the page is loaded, I want to execute a query like SELECT * FROM
AUTHORS WHERE AUTHOR_NAME = Request("AuthorName") or something like
that, rather than like all these examples that show quueries like
SELECT * FROM AUTHORS..
TIA,
AlaguCheck out this article,
http://www.microsoft.com/india/msdn...ol.aspx

Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Alagu" <kolandtech@.gmail.com> wrote in message
news:1105430279.943396.21800@.f14g2000cwb.googlegroups.com...
> Hi all,
> I am looking for some pointers as to how to do paging with datagrid..
> Well, there are so many samples out there.. What I am looking for is to
> be able to have a dynamic query where the user can enter something in a
> text box and search for that and we show the results using a paged
> datagrid..
> When the page is loaded, I want to execute a query like SELECT * FROM
> AUTHORS WHERE AUTHOR_NAME = Request("AuthorName") or something like
> that, rather than like all these examples that show quueries like
> SELECT * FROM AUTHORS..
> TIA,
> Alagu
>

Paging with GridView and Checkbox problem

Hi All, I have a gridview control that gets its data from an objectdatasource control. Inside this gridview, I have a checkbox where the user can select it. I also have a button that is outside of the gridview and when I click on it, I want it to retrieve the value of the checkbox. Here are some code:

<asp:GridView ID="Grid" runat="server" GridLines="None" CellSpacing="2" AllowPaging="true" AllowSorting="true"CellPadding="0" Width="100%" AutoGenerateColumns="False" OnSorting="OnSorting" OnRowCommand="OnRowCommand" DataSourceID="ObjectDataSource"> <Columns> <asp:TemplateField> <ItemTemplate> <input type="checkbox" runat="server" id="SelectRecord" VALUE='<%# Eval("ObjectID") + "+" + Eval("RecordType")%>'/> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title"/> </Columns> <EmptyDataTemplate> <asp:Label runat="server" ID="noResultsFoundLabel" Text="No results found." ForeColor="red"></asp:Label> </EmptyDataTemplate></asp:GridView><asp:ObjectDataSource ID="ObjectDataSource" runat="server" SelectMethod="Get" TypeName="GetWork" OnSelected="OnSelected"> <SelectParameters> <asp:Parameter Direction="Input" Name="recordType" Type="string" DefaultValue=""/> <asp:Parameter Direction="Output" Name="totalRecords" Type="int32"/> </SelectParameters></asp:ObjectDataSource>
 <asp:button runat="server" id="btnClick" text="Click!" OnClick="FindCheckBox" />
 
For my code behind, I have the following:
 
public string FindCheckBox() {if (Page.IsPostBack) {// look for checked boxes HtmlInputCheckBox recordCheckBox;foreach (GridViewRow Itemin Grid.Rows) { recordCheckBox = (HtmlInputCheckBox)Item.Cells[0].FindControl("SelectRecord");if (recordCheckBox !=null && recordCheckBox.Checked)return recordCheckBox.Value; } }return""; }
 The problem occurs when I click on the paging on the gridview. For example, If I have 20 records, and I set each page to display 10 records. So then I would have 2 pages to select from. So in the case
I select page 2, and click on the checkbox of the first record in page 2, and then press the button. I want it to retrieve the value of the first checkbox in the 2nd page. However, the foreach loop is looping
through the GridViewRows in page 1 and not page 2 which keeps giving me the wrong result. Anyone got idea on how I can fix this problem? Thanks. 

Hi,

Based on my understanding, you use ObjectDataSource to retrieve data and display them with GridView, which has a CheckBox column and paging enabled. When the page postbacks, the application always loop the first paging of GridView. If I have misunderstood you, please feel free to let me know.

To better understand your issue, could you please confirm the following information:

Please make sure that we don't bind the GridView before looping this GridView.


Hi Thomas, I believe I have found the problem (although I don't understand why...) and a solution to it.

Basically. I have a master page and a content page. The content page contains two asp panel, one call toolbar and one call grid. the toolbar panel is pass back to the master page and have it render it.

Something like Master.Toolbar = this.toolBar. And on the Master page, I have a Toolbar property that will add it to a placeholder.

public Control Toolbar

{

set { this.placeHolder.add(value); }

}

Everything seems to work properly, except for when a page contains a gridview. It would somehow when i try to do a foreach loop on the grid.rows, it would quit instantly with a rows.count = 0. I play around with it and if I don't pass the toolbar control back to the Master page, then it works fine. However, because the design of passing a control was from an older .NET 1.1 code, many of the pages already use this design so it wouldn't be feasible for me to make the change. Therefore I came up with using a 2nd Content Place Holder and inside that have the orginal PlaceHolder control that will be use by the old pages. And since I remember that if I don't specify using a content inside a content page, the default "content" from the master page will load, I took advantage of it. So all the new pages that uses gridview will use the 2nd content place holder to display the Toolbar, while the older page can be the same without being affected.

Unfortunately, I still don't understand why passing a panel back to a master page for display, while having the event handler "OnClick" code inside my content page will kill the gridview... Hopefully you might be able to enlighten me :)

Thanks.

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

<%@dotnet.itags.org. 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>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:

Quote:

Originally Posted by

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>
>
>
>


thanks Jason!

"Jason Vermillion" wrote:

Quote:

Originally Posted by

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:
>

Quote:

Originally Posted by

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>


No problem, glad to help.

Jason

"Bert" wrote:

Quote:

Originally Posted by

thanks Jason!
>
"Jason Vermillion" wrote:
>

Quote:

Originally Posted by

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:

Quote:

Originally Posted by

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>
>
>
>

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
<%@dotnet.itags.org. 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>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 A
s
> 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>
>
>
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, ByVa
l
> 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:
>
No problem, glad to help.
Jason
"Bert" wrote:
> thanks Jason!
> "Jason Vermillion" wrote:
>

Paging, DataGrid and SQL Server

OK...I have an SQL statement:

SELECT * FROM tblWoof

This has say 1 million rows.
Lets say I want the 2nd page, and my page size is 50.

I could let the DataGrid handle thism but that would mean passing 1 million rows, in a datatable, up through the tiers of my application, when all I want to display is the 2nd block of 50.

It doesn't take a genius to work out that this is bad.

So we create a function:

Public Function FetchWoofs(ByVal StartPage As Integer, ByVal PageLength As Integer) As DataTable
'code here to load data for given page
End Function

Using the Data Adapater we can fill a table with only the data we want using:

Dim da As New System.Data.SqlClient.SqlDataAdapter(SQL, MY_CONN_STRING)
Dim ds As New DataSet
da.Fill(ds, StartPage, PageLength, "Woofs")

The dataset is now filled with only the rows we require...Woohooooo. Good. Way better than passing 1 Million rows up to the UI.

OK. At 1st glance this seems a perfect way of doing things...but.
What actually happens here, is that SQL chucks 1 Million rows to the IIS box, then ADO.NET strips out the rows you require...so this is still not very good. I don't want 1 million records being passed around my network :(

Without using evil JOINS in SQL server on Top x and Not IN Top x-PageLength, and dealing with ordering, is it possible to return JUST the rows you require from SQL Server...ie, is there a function called:

SELECT Rows(50 To 70) *
FROM tblWoofs

?
WokaWell, there is no stright forward TSQL statement like that apart from the Top statement. Though it should be possible with Stored Proc. Sounds like this is what you are looking for.

http://www.aspfaqs.com/webtech/062899-1.shtml

Hope this helps.

Danial
This is what I have been doing.

ALTER PROCEDURE dbo.Contacts_GetContactsPage
(
@.PageSize int,
@.PageIndex int
)
AS
CREATE TABLE #TempTable
(
ContactRowID int IDENTITY(1,1),
ContactKey char(36)
)

INSERT INTO #TempTable (ContactKey)
SELECT Guid FROM Contacts
WHERE EmailAddress != 'web_admin@.pkpromo.com'
ORDER BY LastName, FirstName, MiddleName, EmailAddress

SELECT #TempTable.ContactRowID, Contacts.*
FROM #TempTable
INNER JOIN Contacts ON
Contacts.Guid = #TempTable.ContactKey
WHERE ContactRowID > @.PageSize * @.PageIndex
AND ContactRowID <= @.PageSize * (@.PageIndex+1)
ORDER BY #TempTable.ContactRowID
RETURN

paging,...unable to use datagrid....

hello everyone,

Im currently looking for a method to page my products. I see a lot of articles written on using the datagrid control, only my menu.ascx file uses a form allready, and when I try to add a datagrid to my products.aspx page I get an error not letting me have more than one form.

Does anyone know a way around this? (Adding two forms to a page). Or does anyone know of any good articles on creating paging with a dataList? How would you get your previous and next buttons without a form, if you do use a datalist? Im stuck....

any help would be great, thanks...

-alecThe best thing is to make your web user control without a form (it shouls always be so). And your user control will automatically use the form of the web page.

Paging: Index was outside the bounds of the array

I enable paging for a datagrid in a popup window. The first page works but whenever I clicked on the next link, the following error occurs:

Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:
Line 30: myConnection.Open()
Line 31: myDataSet = New Dataset()
Line 32: myDataAdapter.Fill(myDataSet, "Lead") *** Error
Line 33: myConnection.Close()
Line 34:

I did the same thing in the parent window and it work without any fuss

Below is my code. Sorry if it is messy. I still a newbie

<%@dotnet.itags.org. Page Language="VB" debug="true" %>
<%@dotnet.itags.org. Import Namespace = "System.Data" %>
<%@dotnet.itags.org. Import Namespace = "MySql.Data.MySqlClient" %>

<script language="VB" runat="server">

Dim connectString As String

Sub Page_Load(sender As Object, e As EventArgs)

If Not (IsPostBack)
connectString = CStr(session("findLead"))
END IF

MyDataGrid.PagerStyle.Mode = PagerMode.NextPrev
SearchLead()

End Sub


Function CreateSearchLead() As ICollection

Dim myConnection As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As DataSet


myConnection = New MySqlConnection(";") 'I remove the string


myDataAdapter = New MySqlDataAdapter(connectString, myConnection)
myConnection.Open()
myDataSet = New Dataset()
myDataAdapter.Fill(myDataSet, "Lead")
myConnection.Close()

CreateSearchLead = myDataSet.Tables("Lead").DefaultView

End Function


Sub SearchLead()
MyDataGrid.DataSource = CreateSearchLead()
MyDataGrid.DataBind
End Sub


Sub MyDataGrid_Page(sender As Object, e As DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
SearchLead()
End Sub


Sub MyDataGrid_ItemCommand(Sender As Object, E As DataGridCommandEventArgs)

'Dim Title As String = MyDataGrid.DataKeys(E.Item.ItemIndex)
Dim MyGridButton As LinkButton = E.CommandSource
Dim strURL As String

Select (MyGridButton.CommandName)

Case "Company" :
strURL = "CompanySummary.aspx?company=" & MyGridButton.Text

Case "Name" :
strURL = "LeadSummary.aspx?lead=" & MyGridButton.Text

End Select

session("findLead") = ""

Dim strj As String = "<script language=""javascript"">"
strj = strj & "opener.document.location = '" & strURL & "';window.close();"
strj = strj & "<" & "/script" & ">"
Literal1.Text = strj

' Place the script onto the page...

Page.ClientScript.RegisterStartupScript(GetType(Page),"RedirectScript", strj.ToString())

End Sub


Sub CloseBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

session("findLead") = ""
Response.Write("<script>self.close();" & "<" & "/script>")

End Sub

</script>


<html>
<head>
<title>Popup Lead Search</title>
</head>
<body>

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

<table cellpadding=10 style="font: 10pt verdana">

<ASP:DataGrid id="MyDataGrid" OnItemCommand="MyDataGrid_ItemCommand" DataKeyField="Name" runat="server"
AllowPaging="True"
PageSize="3"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Right"
PagerStyle-NextPageText="Next"
PagerStyle-PrevPageText="Prev"
OnPageIndexChanged="MyDataGrid_Page"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AutoGenerateColumns="false"
AlternatingItemStyle-BackColor="#eeeeee"
>

<Columns>

<asp:TemplateColumn HeaderText="Name">

<ItemTemplate>
<asp:linkbutton Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' CommandName="Name" style="color:darkred" runat="server"/>
</ItemTemplate>

</asp:TemplateColumn>


<asp:TemplateColumn HeaderText="Company">

<ItemTemplate>
<asp:linkbutton Text = '<%# DataBinder.Eval(Container.DataItem, "CompanyName")%>' CommandName="Company" runat="server"/>
</ItemTemplate>

</asp:TemplateColumn>


<asp:TemplateColumn HeaderText="Contact Number">

<ItemTemplate>
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "OfficePhone") %>' style="color:darkred" runat="server"/>
</ItemTemplate>

</asp:TemplateColumn>


<asp:TemplateColumn HeaderText="Date">

<ItemTemplate>
<asp:Label Text = '<%# Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "CreationDate")).ToString("dd/MM/yyyy") %>' runat="server"/>
</ItemTemplate>

</asp:TemplateColumn>

</Columns>

</ASP:DataGrid>


<p>
<asp:button OnClick="CloseBtn_Click" text="Close" runat=server/>
<p>
</form>
</body>
</html>

Any ideas what is wrong?

Thank you

Take a look at the following article:

http://gridviewguy.com/ArticleDetails.aspx?articleID=67

Paging-enabled GridView disappears at postback

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.):
Check stuffs you wanna include in the table:
[] Customer ID
[] Customer Last Name
[] Customer First Name
[] Customer Email
[] Customer Phone
[Click this button to show the table]
[-- the paging-enabled gridview is right here --]
The gridview is declared like so:
<asp:GridView ID="GridView1"
EnableViewState="true"
EnableSortingAndPagingCallbacks="true"
DataSourceID="SqlDataSource1"
runat="server"
AllowPaging="True"
AllowSorting="true">
</asp:GridView>
In the code-behind (in C#), I pass the programmatically created SQL
select command to the SqlDataSource like so:
SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;
Now, after the user clicks the button to create the customer report,
the gridview is populated with customer data with the expected fields.
But, when the paging index is clicked, the gridview disaapears. One
short note from a blog says that gridview will disappear between
postbacks. So, this might be the cause.
I guess I don't need to implement a GridView1_OnPageIndexChanging
method to handle the paging event since I don't think I am manually
binding the gridview to the dataset.
How do we handle this problem? Thanks.On Jan 31, 4:49 am, "antonyliu2...@.yahoo.com"
<antonyliu2...@.yahoo.com> wrote:
> 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.):
> Check stuffs you wanna include in the table:
> [] Customer ID
> [] Customer Last Name
> [] Customer First Name
> [] Customer Email
> [] Customer Phone
> [Click this button to show the table]
> [-- the paging-enabled gridview is right here --]
> The gridview is declared like so:
> <asp:GridView ID="GridView1"
> EnableViewState="true"
> EnableSortingAndPagingCallbacks="true"
> DataSourceID="SqlDataSource1"
> runat="server"
> AllowPaging="True"
> AllowSorting="true">
> </asp:GridView>
> In the code-behind (in C#), I pass the programmatically created SQL
> select command to the SqlDataSource like so:
> SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;
> Now, after the user clicks the button to create the customer report,
> the gridview is populated with customer data with the expected fields.
> But, when the paging index is clicked, the gridview disaapears. One
> short note from a blog says that gridview will disappear between
> postbacks. So, this might be the cause.
> I guess I don't need to implement a GridView1_OnPageIndexChanging
> method to handle the paging event since I don't think I am manually
> binding the gridview to the dataset.
> How do we handle this problem? Thanks.
sound's like you don't bind your grid after postback
Can you please tell us where you do bind it (sample code)?
On Jan 31, 1:36 am, "Alexey Smirnov" <alexey.smir...@.gmail.com> wrote:
> On Jan 31, 4:49 am, "antonyliu2...@.yahoo.com">
> <antonyliu2...@.yahoo.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> sound's like you don't bind your grid after postback
> Can you please tell us where you do bind it (sample code)... Hide quoted te
xt -
>
OK, thanks a lot. I actually mentioned it in my original post. I have
a SqlDataSource control and the GridView is bound to it in the
declaration. I repeat the GridView declaration here:
<asp:GridView ID="GridView1"
EnableViewState="true"
EnableSortingAndPagingCallbacks="true"
DataSourceID="SqlDataSource1"
runat="server"
AllowPaging="True"
AllowSorting="true">
</asp:GridView>
In the code behind, the only thing I programmatically do is to assign
the select command to SqlDataSource1 like so:
SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;
In other words, I don't have anything in code-behind that mannually
binds the data to the gridview, nothing in my code-behind is like
getting a DataSet, SqlDataAdapter, Fills the DataSet, DataBind the
GridView.
That's why I also mentioned that I probably don't have to implement a
method GridView1_OnPageIndexChanging since I am not manually binding
the GridView. I might be wrong, but please advise. Thanks again.

Paging?

I have a table which records user tracks. SessionId column is used to
differtiate between users, nothing else differentiates a user from another.
I
want to write a page where I can list the pages visited by a user, in order.
When a button is pressed I want to show the records for next user.
How can I implement paging?
Thanks for help.When you mean paging are u using any webcontrols?
Patrick
"dotnettester" <dotnettester@.discussions.microsoft.com> wrote in message
news:6551A7E4-3AA5-4E9A-A18E-F60B054BBD21@.microsoft.com...
> I have a table which records user tracks. SessionId column is used to
> differtiate between users, nothing else differentiates a user from
another. I
> want to write a page where I can list the pages visited by a user, in
order.
> When a button is pressed I want to show the records for next user.
> How can I implement paging?
> Thanks for help.
No. I am thinking how to do it'
"Patrick.O.Ige" wrote:

> When you mean paging are u using any webcontrols?
> Patrick
> "dotnettester" <dotnettester@.discussions.microsoft.com> wrote in message
> news:6551A7E4-3AA5-4E9A-A18E-F60B054BBD21@.microsoft.com...
> another. I
> order.
>
>

Paging?

I have a table which records user tracks. SessionId column is used to
differtiate between users, nothing else differentiates a user from another. I
want to write a page where I can list the pages visited by a user, in order.
When a button is pressed I want to show the records for next user.

How can I implement paging?

Thanks for help.When you mean paging are u using any webcontrols?
Patrick

"dotnettester" <dotnettester@.discussions.microsoft.com> wrote in message
news:6551A7E4-3AA5-4E9A-A18E-F60B054BBD21@.microsoft.com...
> I have a table which records user tracks. SessionId column is used to
> differtiate between users, nothing else differentiates a user from
another. I
> want to write a page where I can list the pages visited by a user, in
order.
> When a button is pressed I want to show the records for next user.
> How can I implement paging?
> Thanks for help.
When you mean paging are u using any webcontrols?
Patrick

"dotnettester" <dotnettester@.discussions.microsoft.com> wrote in message
news:6551A7E4-3AA5-4E9A-A18E-F60B054BBD21@.microsoft.com...
> I have a table which records user tracks. SessionId column is used to
> differtiate between users, nothing else differentiates a user from
another. I
> want to write a page where I can list the pages visited by a user, in
order.
> When a button is pressed I want to show the records for next user.
> How can I implement paging?
> Thanks for help.
No. I am thinking how to do it??

"Patrick.O.Ige" wrote:

> When you mean paging are u using any webcontrols?
> Patrick
> "dotnettester" <dotnettester@.discussions.microsoft.com> wrote in message
> news:6551A7E4-3AA5-4E9A-A18E-F60B054BBD21@.microsoft.com...
> > I have a table which records user tracks. SessionId column is used to
> > differtiate between users, nothing else differentiates a user from
> another. I
> > want to write a page where I can list the pages visited by a user, in
> order.
> > When a button is pressed I want to show the records for next user.
> > How can I implement paging?
> > Thanks for help.
>

painfully ignorant but frustrating

I HAVE looked around but cant figure out the stupid mistake I'm
making. I am POSTing a form and in the CodeBehind function for the
submit i am simply building a SQL statement, however, I cant seem to
retrieve the correct (newly selected) values for the dropdownlist
controls. I'm sorry, i know this is elementary but I just cant see my
error - anyone give me the lowdown?!

SQL string below: (Im trying both the selected item & index but both
give the original value when first rendered)...

INSERT INTO Team " +
"(TeamName, Email, fkManufacturerId," +
"fkDriver1Id, fkDriver2Id, fkDriver3Id," +
"fkTyreId,Paid) " +
" VALUES " +
"('" + txtTeamName.Text + "'," +
"'" + txtUserId.Text + "'," +
ddlManufacturer.SelectedIndex + "," +
ddlDriver1.SelectedItem.Value + "," +
ddlDriver2.SelectedItem.Value + "," +
ddlDriver3.SelectedItem.Text + "," +
ddlTyre.SelectedItem.Value + "," +
"False);";

cheers, danTHANKYOU Corey! - Perfect answer and as i said, a real simple
(obvious) mistake which i just couldnt see!

Kind regards, dan
Your post went unanswered. Have you resolved this issue?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"dan m" <dan@.grandprix.freeserve.co.uk> wrote in message
news:7ffa57ad.0402061535.746a3715@.posting.google.c om...
> I HAVE looked around but cant figure out the stupid mistake I'm
> making. I am POSTing a form and in the CodeBehind function for the
> submit i am simply building a SQL statement, however, I cant seem to
> retrieve the correct (newly selected) values for the dropdownlist
> controls. I'm sorry, i know this is elementary but I just cant see my
> error - anyone give me the lowdown?!
> SQL string below: (Im trying both the selected item & index but both
> give the original value when first rendered)...
> INSERT INTO Team " +
> "(TeamName, Email, fkManufacturerId," +
> "fkDriver1Id, fkDriver2Id, fkDriver3Id," +
> "fkTyreId,Paid) " +
> " VALUES " +
> "('" + txtTeamName.Text + "'," +
> "'" + txtUserId.Text + "'," +
> ddlManufacturer.SelectedIndex + "," +
> ddlDriver1.SelectedItem.Value + "," +
> ddlDriver2.SelectedItem.Value + "," +
> ddlDriver3.SelectedItem.Text + "," +
> ddlTyre.SelectedItem.Value + "," +
> "False);";
> cheers, dan

Paid web site

Can any one tell me if there is a paid asp.net website where only experts answers the questions. thanks

The only paid forum I know is experts-exchange, which covers different programming languages.


Good question. I don't know of any, but you can always pay microsoft on a per support call to answer questions. I'm curious if you are not getting answers here you need? There are an awful lot of experts here rushing to answer questions. Many are asp.net professionals, authors and instructors. I suspect if there were one, it would be for more detailed problems that go beyond the scope of basic questions like are answered here. You might want to try one of the for hire programmer web sites like rent-a-coder. http://www.rentacoder.com/RentACoder/default.asp


The benefit of this forum is that you have very good quality professionals that answer your questions from different point of view. We all share our experience.

This is something you cannot find easily.


I think you can post your problem in jobs section with payment details and then developers may respond to you.


Asp.Net form has been very helpful to me, however, I have the following suggestions to improve on ..

1- Cut down the time to get an answer.

2- Do not allow everyone to answer the question as one may waste a lot of time by following an inferior response. User could be allowed to preselect the threshold.

3- Further, there is no provision for experts to escalate/forward the question to more appropriate experts.

4- Give provision to mark the answer as inferior or superior. So the experts are on their toes when responding.

All in all the website is very good!

Paging-enabled GridView disappears at postback

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.):

Check stuffs you wanna include in the table:

[] Customer ID
[] Customer Last Name
[] Customer First Name
[] Customer Email
[] Customer Phone

[Click this button to show the table]

[-- the paging-enabled gridview is right here --]

The gridview is declared like so:

<asp:GridView ID="GridView1"
EnableViewState="true"
EnableSortingAndPagingCallbacks="true"
DataSourceID="SqlDataSource1"
runat="server"
AllowPaging="True"
AllowSorting="true">
</asp:GridView>

In the code-behind (in C#), I pass the programmatically created SQL
select command to the SqlDataSource like so:

SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;

Now, after the user clicks the button to create the customer report,
the gridview is populated with customer data with the expected fields.

But, when the paging index is clicked, the gridview disaapears. One
short note from a blog says that gridview will disappear between
postbacks. So, this might be the cause.

I guess I don't need to implement a GridView1_OnPageIndexChanging
method to handle the paging event since I don't think I am manually
binding the gridview to the dataset.

How do we handle this problem? Thanks.On Jan 31, 4:49 am, "antonyliu2...@.yahoo.com"
<antonyliu2...@.yahoo.comwrote:

Quote:

Originally Posted 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.):
>
Check stuffs you wanna include in the table:
>
[] Customer ID
[] Customer Last Name
[] Customer First Name
[] Customer Email
[] Customer Phone
>
[Click this button to show the table]
>
[-- the paging-enabled gridview is right here --]
>
The gridview is declared like so:
>
<asp:GridView ID="GridView1"
EnableViewState="true"
EnableSortingAndPagingCallbacks="true"
DataSourceID="SqlDataSource1"
runat="server"
AllowPaging="True"
AllowSorting="true">
</asp:GridView>
>
In the code-behind (in C#), I pass the programmatically created SQL
select command to the SqlDataSource like so:
>
SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;
>
Now, after the user clicks the button to create the customer report,
the gridview is populated with customer data with the expected fields.
>
But, when the paging index is clicked, the gridview disaapears. One
short note from a blog says that gridview will disappear between
postbacks. So, this might be the cause.
>
I guess I don't need to implement a GridView1_OnPageIndexChanging
method to handle the paging event since I don't think I am manually
binding the gridview to the dataset.
>
How do we handle this problem? Thanks.


sound's like you don't bind your grid after postback

Can you please tell us where you do bind it (sample code)?
On Jan 31, 1:36 am, "Alexey Smirnov" <alexey.smir...@.gmail.comwrote:

Quote:

Originally Posted by

On Jan 31, 4:49 am, "antonyliu2...@.yahoo.com">
>
<antonyliu2...@.yahoo.comwrote:

Quote:

Originally Posted by

I've been googling for some time, and could not find the solution to
this problem.


>

Quote:

Originally Posted by

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.


>

Quote:

Originally Posted by

The web form looks like so (Don't worry about the stupidity of this
web form for now.):


>

Quote:

Originally Posted by

Check stuffs you wanna include in the table:


>

Quote:

Originally Posted by

[] Customer ID
[] Customer Last Name
[] Customer First Name
[] Customer Email
[] Customer Phone


>

Quote:

Originally Posted by

[Click this button to show the table]


>

Quote:

Originally Posted by

[-- the paging-enabled gridview is right here --]


>

Quote:

Originally Posted by

The gridview is declared like so:


>

Quote:

Originally Posted by

<asp:GridView ID="GridView1"
EnableViewState="true"
EnableSortingAndPagingCallbacks="true"
DataSourceID="SqlDataSource1"
runat="server"
AllowPaging="True"
AllowSorting="true">
</asp:GridView>


>

Quote:

Originally Posted by

In the code-behind (in C#), I pass the programmatically created SQL
select command to the SqlDataSource like so:


>

Quote:

Originally Posted by

SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;


>

Quote:

Originally Posted by

Now, after the user clicks the button to create the customer report,
the gridview is populated with customer data with the expected fields.


>

Quote:

Originally Posted by

But, when the paging index is clicked, the gridview disaapears. One
short note from a blog says that gridview will disappear between
postbacks. So, this might be the cause.


>

Quote:

Originally Posted by

I guess I don't need to implement a GridView1_OnPageIndexChanging
method to handle the paging event since I don't think I am manually
binding the gridview to the dataset.


>

Quote:

Originally Posted by

How do we handle this problem? Thanks.


>
sound's like you don't bind your grid after postback
>
Can you please tell us where you do bind it (sample code)?- Hide quoted text -
>


OK, thanks a lot. I actually mentioned it in my original post. I have
a SqlDataSource control and the GridView is bound to it in the
declaration. I repeat the GridView declaration here:

<asp:GridView ID="GridView1"
EnableViewState="true"
EnableSortingAndPagingCallbacks="true"
DataSourceID="SqlDataSource1"
runat="server"
AllowPaging="True"
AllowSorting="true">
</asp:GridView>

In the code behind, the only thing I programmatically do is to assign
the select command to SqlDataSource1 like so:

SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;

In other words, I don't have anything in code-behind that mannually
binds the data to the gridview, nothing in my code-behind is like
getting a DataSet, SqlDataAdapter, Fills the DataSet, DataBind the
GridView.

That's why I also mentioned that I probably don't have to implement a
method GridView1_OnPageIndexChanging since I am not manually binding
the GridView. I might be wrong, but please advise. Thanks again.