473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

DataGrid paging Question

Pat
I have a 2 nested Datagrid. When i select a row in the Master Datagrid i
populate the Child databrid using myDataGrid.SelectedIndex value
as the filter and setting the DataKeyField.
I enabled paging for the MasterDataGrid which works well but when i page to
the next set of rows and select a particular ROW(for example SHOW DETAILS)
to populated the Child Datagrid after paging to the next page it doesn't
work..
it just sends me back to the previous page ..
I have myDataGrid.CurrentPageIndex = 0 because i'm populating "myDataGrid"
and seletcing a dropdown list..
Any ideas

Try
objConn.Open()
da.Fill(dt, "Orders")

myDataGrid.DataSource = dt
myDataGrid.DataMember = "CMRC_Orders"
myDataGrid.DataKeyField = "OrderID"
myDataGrid.CurrentPageIndex = 0
myDataGrid.DataBind()

Catch ex As SqlException
dtExceptionLabel.Text = ex.Message
Finally
objConn.Close()
End Try
Nov 19 '05 #1
3 1807
Pat,

If you bind your grid every time and also set the current page index on
binding your grid will always default back to the current page index you're
exlicitly setting.

Try something like this:

Only bind your grid when you need to. Put your grid binding into its own
subroutine and give the subroutine a pageIndex property and call it once on
page load by using:

Private Sub BindByGrid(ByVal pageIndex As Int32)
Try
objConn.Open()
da.Fill(dt, "Orders")
myDataGrid.DataSource = dt
myDataGrid.DataMember = "CMRC_Orders"
myDataGrid.DataKeyField = "OrderID"
myDataGrid.CurrentPageIndex = pageIndex
myDataGrid.DataBind()
Catch ex As SqlException
dtExceptionLabel.Text = ex.Message
Finally
objConn.Close()
End Try
End Sub

If Not IsPostBack Then
Call BindMyGrid(0)
End If

'---Then use the datagrid's PageIndexChanged sub to call your binding again:

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
DataGrid1.PageIndexChanged
Try
Call BindMyGrid(e.NewPageIndex)
Catch ex As Exception
'---Handle Errors Here
End Try
End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Pat" <na********@hotmail.com> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
I have a 2 nested Datagrid. When i select a row in the Master Datagrid i
populate the Child databrid using myDataGrid.SelectedIndex value
as the filter and setting the DataKeyField.
I enabled paging for the MasterDataGrid which works well but when i page
to
the next set of rows and select a particular ROW(for example SHOW DETAILS)
to populated the Child Datagrid after paging to the next page it doesn't
work..
it just sends me back to the previous page ..
I have myDataGrid.CurrentPageIndex = 0 because i'm populating
"myDataGrid"
and seletcing a dropdown list..
Any ideas

Try
objConn.Open()
da.Fill(dt, "Orders")

myDataGrid.DataSource = dt
myDataGrid.DataMember = "CMRC_Orders"
myDataGrid.DataKeyField = "OrderID"
myDataGrid.CurrentPageIndex = 0
myDataGrid.DataBind()

Catch ex As SqlException
dtExceptionLabel.Text = ex.Message
Finally
objConn.Close()
End Try

Nov 19 '05 #2
Pat
Thx for the reply..when i set "myDataGrid.CurrentPageIndex =0"
before i also didn't get the error anymore but i'm facing one more problem
since my Datagrid is poplulated based on what is selected in the
dropdownlist below:-

If Not Page.IsPostBack Then
Dim da As SqlDataAdapter
Dim dt As DataSet
da = New SqlDataAdapter("Select CompanyID, CompanyName from
CMRC_Company", myConnection)
dt = New DataSet
Try
myConnection.Open()
da.Fill(dt, "CMRC_Company")
myDropDownList.DataSource = dt
' dtgProducts.DataMember = "Products"
myDropDownList.DataBind()

Catch ex As SqlException
'dtExceptionLabel.Text = ex.Message
Response.Write("An error has occurred: " & ex.ToString())
Finally
If Not myConnection Is Nothing Then
myConnection.Close()
End If
myDropDownList.Items.Insert(0, "Select an Item")
myDropDownList.SelectedIndex = 0
End Try

End If

After clicking on NEXT to do paging and i select a ROW(selectedindex) of
the Datagrid it just takes me back to the default page.
But when i first load the page after selecting a company from the
dropdlownlist and my Datagrid populates and then click on a ROW to populate
my second datagrisd it works fine but after paging to the next level it
doesn't work and sends me back to the previous page..
Any ideas
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2*****************@TK2MSFTNGP10.phx.gbl...
Pat,

If you bind your grid every time and also set the current page index on
binding your grid will always default back to the current page index you're exlicitly setting.

Try something like this:

Only bind your grid when you need to. Put your grid binding into its own
subroutine and give the subroutine a pageIndex property and call it once on page load by using:

Private Sub BindByGrid(ByVal pageIndex As Int32)
Try
objConn.Open()
da.Fill(dt, "Orders")
myDataGrid.DataSource = dt
myDataGrid.DataMember = "CMRC_Orders"
myDataGrid.DataKeyField = "OrderID"
myDataGrid.CurrentPageIndex = pageIndex
myDataGrid.DataBind()
Catch ex As SqlException
dtExceptionLabel.Text = ex.Message
Finally
objConn.Close()
End Try
End Sub

If Not IsPostBack Then
Call BindMyGrid(0)
End If

'---Then use the datagrid's PageIndexChanged sub to call your binding again:
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
DataGrid1.PageIndexChanged
Try
Call BindMyGrid(e.NewPageIndex)
Catch ex As Exception
'---Handle Errors Here
End Try
End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Pat" <na********@hotmail.com> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
I have a 2 nested Datagrid. When i select a row in the Master Datagrid i
populate the Child databrid using myDataGrid.SelectedIndex value
as the filter and setting the DataKeyField.
I enabled paging for the MasterDataGrid which works well but when i page
to
the next set of rows and select a particular ROW(for example SHOW DETAILS) to populated the Child Datagrid after paging to the next page it doesn't
work..
it just sends me back to the previous page ..
I have myDataGrid.CurrentPageIndex = 0 because i'm populating
"myDataGrid"
and seletcing a dropdown list..
Any ideas

Try
objConn.Open()
da.Fill(dt, "Orders")

myDataGrid.DataSource = dt
myDataGrid.DataMember = "CMRC_Orders"
myDataGrid.DataKeyField = "OrderID"
myDataGrid.CurrentPageIndex = 0
myDataGrid.DataBind()

Catch ex As SqlException
dtExceptionLabel.Text = ex.Message
Finally
objConn.Close()
End Try


Nov 19 '05 #3
Pat,

You'll have to store all variables that determine what info is being
databound between postbacks. Then on postback get the proper data based on
those same variables.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Pat" <na********@hotmail.com> wrote in message
news:OW**************@TK2MSFTNGP12.phx.gbl...
Thx for the reply..when i set "myDataGrid.CurrentPageIndex =0"
before i also didn't get the error anymore but i'm facing one more problem
since my Datagrid is poplulated based on what is selected in the
dropdownlist below:-

If Not Page.IsPostBack Then
Dim da As SqlDataAdapter
Dim dt As DataSet
da = New SqlDataAdapter("Select CompanyID, CompanyName from
CMRC_Company", myConnection)
dt = New DataSet
Try
myConnection.Open()
da.Fill(dt, "CMRC_Company")
myDropDownList.DataSource = dt
' dtgProducts.DataMember = "Products"
myDropDownList.DataBind()

Catch ex As SqlException
'dtExceptionLabel.Text = ex.Message
Response.Write("An error has occurred: " & ex.ToString())
Finally
If Not myConnection Is Nothing Then
myConnection.Close()
End If
myDropDownList.Items.Insert(0, "Select an Item")
myDropDownList.SelectedIndex = 0
End Try

End If

After clicking on NEXT to do paging and i select a ROW(selectedindex) of
the Datagrid it just takes me back to the default page.
But when i first load the page after selecting a company from the
dropdlownlist and my Datagrid populates and then click on a ROW to
populate
my second datagrisd it works fine but after paging to the next level it
doesn't work and sends me back to the previous page..
Any ideas
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2*****************@TK2MSFTNGP10.phx.gbl...
Pat,

If you bind your grid every time and also set the current page index on
binding your grid will always default back to the current page index

you're
exlicitly setting.

Try something like this:

Only bind your grid when you need to. Put your grid binding into its own
subroutine and give the subroutine a pageIndex property and call it once

on
page load by using:

Private Sub BindByGrid(ByVal pageIndex As Int32)
Try
objConn.Open()
da.Fill(dt, "Orders")
myDataGrid.DataSource = dt
myDataGrid.DataMember = "CMRC_Orders"
myDataGrid.DataKeyField = "OrderID"
myDataGrid.CurrentPageIndex = pageIndex
myDataGrid.DataBind()
Catch ex As SqlException
dtExceptionLabel.Text = ex.Message
Finally
objConn.Close()
End Try
End Sub

If Not IsPostBack Then
Call BindMyGrid(0)
End If

'---Then use the datagrid's PageIndexChanged sub to call your binding

again:

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
DataGrid1.PageIndexChanged
Try
Call BindMyGrid(e.NewPageIndex)
Catch ex As Exception
'---Handle Errors Here
End Try
End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Pat" <na********@hotmail.com> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
>I have a 2 nested Datagrid. When i select a row in the Master Datagrid i
> populate the Child databrid using myDataGrid.SelectedIndex value
> as the filter and setting the DataKeyField.
> I enabled paging for the MasterDataGrid which works well but when i
> page
> to
> the next set of rows and select a particular ROW(for example SHOW DETAILS) > to populated the Child Datagrid after paging to the next page it
> doesn't
> work..
> it just sends me back to the previous page ..
> I have myDataGrid.CurrentPageIndex = 0 because i'm populating
> "myDataGrid"
> and seletcing a dropdown list..
> Any ideas
>
> Try
> objConn.Open()
> da.Fill(dt, "Orders")
>
> myDataGrid.DataSource = dt
> myDataGrid.DataMember = "CMRC_Orders"
> myDataGrid.DataKeyField = "OrderID"
> myDataGrid.CurrentPageIndex = 0
> myDataGrid.DataBind()
>
> Catch ex As SqlException
> dtExceptionLabel.Text = ex.Message
> Finally
> objConn.Close()
> End Try
>
>



Nov 19 '05 #4

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

Similar topics

1
by: iforsyth | last post by:
Have a paging datagrid with a checkbox control in column(0). ViewState is enabled. I check the checkbox in first row of the grid on a page and then the program hits this event: Private Sub...
2
by: Daniel Walzenbach | last post by:
Hi, I have a question regarding the DataGrid control. If paging is enabled the grid binds the data, sets the paging on the top/bottom (or however it is set up) and throws away unnecessary...
0
by: wh1974 | last post by:
I've found several posts on the question that I'm about to ask but have found that all link to a page on a website requiring a subscription. The problem I'm having is that in the paging row of a...
6
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP...
3
by: Danky | last post by:
Hello Masters! Anyone can help me with the datagrid, well, the app load a lot of data from DB and it show on the datagrid, and well, I need to allow paging and.... the issue is with the event...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
3
by: GD | last post by:
Got a simple ASPX page (.NET v1.1) with a DataGrid displaying a list of widgets. If the page has a QueryString called WidgetId specific, I need to automatically mark the specific DataGridItem as...
0
by: JimSnotes | last post by:
Hello, Does anybody know if you can use the PagedDataSource class in conjunction with a DataGrid in an ASP.NET 1.1 VB web page? I know that the DataGrid already has built in paging...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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

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