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