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")
' ?
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")
' ?