Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Allow paging for a DataGrid


Message #1 by "CMY" <my62202@y...> on Mon, 30 Sep 2002 08:31:50
Hi all,

I had encounter the following problem and would like to get some help.
Thanks a lot.

I had a button, btnClick and whenever I clicked on this button, it will 
retrieve the data and populate to the data grid.

As for the data grid, dgCustomer, I had set the AllowPaging property to 
True and Page size is 10 and Mode is Page numbers.

Below is my code :

dim strSql as string
dim da as sqlDataAdapter
dim ds as new DataSet()

for btnClick button event, 

        strSql = "select * from customer"
        da = New SqlDataAdapter(strSql, conn)
        da.Fill(ds)
        dgCustomer.DataSource = ds
        dgCustomer.DataBind()


for dgCustomer_PageIndexChanged event,

        dgResults.CurrentPageIndex = e.NewPageIndex
        dgResults.DataSource = dsResult
        dgResults.DataBind()


Right now, the problem is for the first time i click on btnClick, it will 
display the first 10 data to the dgCustomer data grid.

But subsequent, when I click on page 2 at the end of the data grid, it 
does not display the next 10 data to the data grid automatically. But I 
have to click on the btnClick again then only it will show me the next 10 
data.

Is there anything wrong with my coding in the PageIndexChanged event that 
makes it don't display the subsequent data automatically ?
Message #2 by ramprasad upadhyaya <rpu_forum@y...> on Mon, 30 Sep 2002 01:36:17 -0700 (PDT)
 The reason is simple.... U R getting the data in the button click event. obviously the paging property will reset if u click on
paging links...
  The solution is very simple.... Follow the sequence
1. Remove the code from button click event and create a new function and paste the code..as
---------------------------
function fncBindData()
strSql = "select * from customer"
da = New SqlDataAdapter(strSql, conn)
da.Fill(ds)
dgCustomer.DataSource = ds
dgCustomer.DataBind()

end function

-----------------------------------------------


2. Call this function in Page onload as 
------------------------------------------------

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

fncBindData

end sub

-----------------------------------------------------------------------

3. Just put below code in pageindexchanged event

Private Sub grdRes_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles grdRes.PageIndexChanged

grdRes.CurrentPageIndex = e.NewPageIndex

fncBindData()

End Sub

Thats all ...

Let me know whether u r problem is solved..

Ramprasad

 

 

 CMY wrote:Hi all,

I had encounter the following problem and would like to get some help.
Thanks a lot.

I had a button, btnClick and whenever I clicked on this button, it will 
retrieve the data and populate to the data grid.

As for the data grid, dgCustomer, I had set the AllowPaging property to 
True and Page size is 10 and Mode is Page numbers.

Below is my code :

dim strSql as string
dim da as sqlDataAdapter
dim ds as new DataSet()

for btnClick button event, 

strSql = "select * from customer"
da = New SqlDataAdapter(strSql, conn)
da.Fill(ds)
dgCustomer.DataSource = ds
dgCustomer.DataBind()


for dgCustomer_PageIndexChanged event,

dgResults.CurrentPageIndex = e.NewPageIndex
dgResults.DataSource = dsResult
dgResults.DataBind()


Right now, the problem is for the first time i click on btnClick, it will 
display the first 10 data to the dgCustomer data grid.

But subsequent, when I click on page 2 at the end of the data grid, it 
does not display the next 10 data to the data grid automatically. But I 
have to click on the btnClick again then only it will show me the next 10 
data.

Is there anything wrong with my coding in the PageIndexChanged event that 
makes it don't display the subsequent data automatically ?
---
Beginning ASP.NET Databases using VB.NET
http://www.wrox.com/ACON11.asp?ISBN=1861006195

Beginning ASP.NET Databases using C#
http://www.wrox.com/ACON11.asp?ISBN=1861007418

These books look at how we can create data-centric ASP.NET 
applications. Requiring some basic knowledge of ASP.NET, 
Access and SQL the authors guide you through the process 
of connecting and consuming information in a variety of 
ways. They are packed full of excellent illustrative code 
examples, demonstrating important fundamental principles.


Regards,

Ramprasad Upadhyaya



---------------------------------
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
Message #3 by "CMY" <my62202@y...> on Mon, 30 Sep 2002 10:23:35
Hi Ramprasad,

Can I don't call the function fncBindData() on Page onload event ?
Because the strSql might not be "select * from customer", the database 
depend on the table selected by user from a drop down list. So, I only 
want to display the data to the datagrid whenever the user click on the 
btnClick, so that I can concatenate the table name to the strSql.

#############################
> 
 The reason is simple.... U R getting the data in the button click event. 
obviously the paging property will reset if u click on paging links...
  The solution is very simple.... Follow the sequence
1. Remove the code from button click event and create a new function and 
paste the code..as
---------------------------
function fncBindData()
strSql = "select * from customer"
da = New SqlDataAdapter(strSql, conn)
da.Fill(ds)
dgCustomer.DataSource = ds
dgCustomer.DataBind()

end function

-----------------------------------------------


2. Call this function in Page onload as 
------------------------------------------------

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

fncBindData

end sub

-----------------------------------------------------------------------

3. Just put below code in pageindexchanged event

Private Sub grdRes_PageIndexChanged(ByVal source As Object, ByVal e As 
System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles 
grdRes.PageIndexChanged

grdRes.CurrentPageIndex = e.NewPageIndex

fncBindData()

End Sub

Thats all ...

Let me know whether u r problem is solved..

Ramprasad

 

 

 CMY wrote:Hi all,

I had encounter the following problem and would like to get some help.
Thanks a lot.

I had a button, btnClick and whenever I clicked on this button, it will 
retrieve the data and populate to the data grid.

As for the data grid, dgCustomer, I had set the AllowPaging property to 
True and Page size is 10 and Mode is Page numbers.

Below is my code :

dim strSql as string
dim da as sqlDataAdapter
dim ds as new DataSet()

for btnClick button event, 

strSql = "select * from customer"
da = New SqlDataAdapter(strSql, conn)
da.Fill(ds)
dgCustomer.DataSource = ds
dgCustomer.DataBind()


for dgCustomer_PageIndexChanged event,

dgResults.CurrentPageIndex = e.NewPageIndex
dgResults.DataSource = dsResult
dgResults.DataBind()


Right now, the problem is for the first time i click on btnClick, it will 
display the first 10 data to the dgCustomer data grid.

But subsequent, when I click on page 2 at the end of the data grid, it 
does not display the next 10 data to the data grid automatically. But I 
have to click on the btnClick again then only it will show me the next 10 
data.

Is there anything wrong with my coding in the PageIndexChanged event that 
makes it don't display the subsequent data automatically ?
---
Beginning ASP.NET Databases using VB.NET
http://www.wrox.com/ACON11.asp?ISBN=1861006195

Beginning ASP.NET Databases using C#
http://www.wrox.com/ACON11.asp?ISBN=1861007418

These books look at how we can create data-centric ASP.NET 
applications. Requiring some basic knowledge of ASP.NET, 
Access and SQL the authors guide you through the process 
of connecting and consuming information in a variety of 
ways. They are packed full of excellent illustrative code 
examples, demonstrating important fundamental principles.


Regards,

Ramprasad Upadhyaya



---------------------------------
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!

  Return to Index