472,992 Members | 3,304 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

datagrid error on change page (VB.ASP.NET)

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). This code doesn't even run unless a button in the datagrid is
clicked, but is erroring out the page when I click page 2,3,etc.

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 in
advance!

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

'code that the error is occurring in when page changed
'contains code for buttons inside template columns in datagrid
'in the .aspx file the datagrid's OnItemCommand property
'is set to reference this sub:
' OnItemCommand="ExecuteDataGridCommands"
Public Sub ExecuteDataGridCommands(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

'reference textbox "txtID" inside current row of datagrid
Dim txtID As TextBox

'the following line is where the error occurs:
txtID = DataGrid1.Items(e.Item.ItemIndex).FindControl("txt ID")

' i tried this instead, a paging error doesnt occur,
' but this line causes a different error (control not found):
' txtID = DataGrid1.FindControl("txtID")

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

etc.

Jul 21 '05 #1
1 2180
I figured it out...

Evidently the datagrid template columns code is evaluated when a change
page event happens, and at the moment it is evaluated, the current
datagrid item is -1. Simply putting in a check for -1 solved the
probrem:

Public Sub ExecuteDataGridCommands(ByVal sender As Object, ByVal e
As DataGridCommandEventArgs)
If e.Item.ItemIndex > -1 Then
Dim txtID As TextBox
txtID =
DataGrid1.Items(e.Item.ItemIndex).FindControl("txt ID")

Mad Scientist Jr wrote:
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). This code doesn't even run unless a button in the datagrid is clicked, but is erroring out the page when I click page 2,3,etc.


Jul 21 '05 #2

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

Similar topics

6
by: John Lau | last post by:
Hi, I am looking at the MS KB Article 306355: HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C# .NET This article describes how to redirect errors to a custom html...
6
by: Dee | last post by:
Hi The paging numbers of my DataGrid dont actually page. What can be the cause? Everyting else seems to work. Thanks Dee
9
by: Patrick | last post by:
I have an ASP.NET page that searches for someone in the corporate Active Directory. It had been working fine until recently when I changed from Basic Authentication on IIS6 back to Integrated...
1
by: Mad Scientist Jr | last post by:
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). This code doesn't even run unless a button in...
0
by: gokulrajad | last post by:
Hi there, Iam trying to create a datagrid dynamically in asp .net (C#). It contains a leftmost column with the check box and few data columns and the last column is a hyperlink column. Please find...
1
by: Yanesh Tyagi | last post by:
Hi All have a web page named itemList.aspx. It contains a datagrid (id = datagrid1). The web form also have a user control named itemSearch.ascx. This user control have several options to search...
2
by: Brian Tkatch | last post by:
How do i detect a datagrid row change? Currently, i have a few datagrids that i keep in sync, refreshing from the database whenver a row changes. I would like to avoid CurrentCellChanged because...
0
by: shapper | last post by:
Hello, I created a web site, using VS2005 and Asp.Net 2.0, which is working fine in my computer. I then compiled the web site and uploaded it to my server. Everything works fine but I can't...
1
by: shikhargilhotra | last post by:
Hi All, I hav a datagrid on my asp.net platform..But itz not loading when i execute it...(or run the program...lets say a simplest one),,,,other controls are loading perfectly.....written below...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.