473,603 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_PageI ndexChanged(ByV al source As Object, ByVal e
As System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles
DataGrid1.PageI ndexChanged
DataGrid1.Curre ntPageIndex = 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=" ExecuteDataGrid Commands"
Public Sub ExecuteDataGrid Commands(ByVal sender As Object, ByVal e As
DataGridCommand EventArgs)

'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.ItemInd ex).FindControl ("txtID")

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

'someone suggested this method, but it didn't work
'Dim iIndex As Int32
'iIndex = e.Item.ItemInde x - (DataGrid1.Curr entPageIndex *
DataGrid1.PageS ize)
'txtID = DataGrid1.Items (iIndex).FindCo ntrol("txtID")

etc.

Jul 21 '05 #1
1 2238
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 ExecuteDataGrid Commands(ByVal sender As Object, ByVal e
As DataGridCommand EventArgs)
If e.Item.ItemInde x > -1 Then
Dim txtID As TextBox
txtID =
DataGrid1.Items (e.Item.ItemInd ex).FindControl ("txtID")

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
3557
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 error page. All six steps in the article work just fine. Then at the end of the article, there is a little comment about redirecting errors to an aspx page (instead of an html page):
6
1445
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
3166
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 Windows authentication. The error occurs on the FindAll method. The exceptions are as follows. anyway of getting the code working with Integrated Windows authentication (too annoying for user to enter user-name/password). Note I do need to use...
1
252
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 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...
0
1183
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 the code attached below. The sorting, paging also doesnt work. private void BuildDataGrid() {
1
1317
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 and a submit button. I want to change the datasource property of datagrid1 on the click of submit button. As the datagrid1 is on the itemList.aspx page and the submit button is on the user control, I connot access the datagrid directly. Is there...
2
7704
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 changing a cell within the same row causes an uneccesary DB call. Also, when the row changed to is the "new" row, nothing should happen. I wrote some code, which indeed works, but would like to know if i am missing something more obvious.
0
1049
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 access to a page: News.aspx. I get the 500 browser error! This page works fine in my computer and I can't find anything else different in it then in othe pages.
1
933
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 is d code.... A quick help will b appreciated... thx Shikhar PROGRAM ##### using System.Data.SqlClient;
0
7996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7928
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8415
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8405
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6735
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.