datagrid page index change event error

  • Thread starter Mad Scientist Jr
  • Start date
M

Mad Scientist Jr

I am getting an error in my code that references a textbox inside the
current row of my datagrid, whenever I try changing the page (paging is
enabled). I have tried a few different notations without any luck. Can
someone look at the lines below and tell me what might be wrong?
Thanks...


'event to change page:
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
Call BindGrid() ' bind data to the datagrid
End Sub

'contains code for buttons inside template columns in datagrid
'datagrid1's OnItemCommand="ExecuteDataGridCommands" (name of this
sub):
Public Sub ExecuteDataGridCommands(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
'reference textbox "txtID" inside current row of datagrid
Dim txtID As TextBox
'incorrect, but doesnt break on datagrid page 2: txtID =
DataGrid1.FindControl("txtID")
'correct, but doesnt work on page 2: txtID =
DataGrid1.Items(e.Item.ItemIndex).FindControl("txtID")

'another method someone suggested, didn't work
Dim iIndex As Int32
iIndex = e.Item.ItemIndex - (DataGrid1.CurrentPageIndex *
DataGrid1.PageSize)
txtID = DataGrid1.Items(iIndex).FindControl("txtID")

' ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top