473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Can anybody help with this code?

Can anybody tell me what is wrong with this code? I would really appreciate
some help here.
The data grid has 4 columns (0,1,2,3), and 1 is not visible.
Whenever I click Edit, I get this error:
_____________________________

Specified argument was out of the range of valid values. Parameter name:
index
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified argument
was out of the range of valid values. Parameter name: index

Source Error:

Line 131: Sub dgUpdate(ByVal s As Object, ByVal e As
DataGridCommandEventArgs) Handles dg.ItemCommand
Line 132: con.Open()
Line 133: Dim txtDescr As TextBox = e.Item.Cells(1).Controls(0)
Line 134: Dim txtPrice As TextBox = e.Item.Cells(2).Controls(0)
Line 135: Dim strProdID As String = e.Item.Cells(1).Text
Source File: C:\Inetpub\wwwroot\Copy_of_WebApplication2\product s.aspx.vb
Line: 133

Stack Trace:

[ArgumentOutOfRangeException: Specified argument was out of the range of
valid values.
Parameter name: index]
System.Web.UI.ControlCollection.get_Item(Int32 index) +58
WebApplication2.products.dgUpdate(Object s, DataGridCommandEventArgs e)
in C:\Inetpub\wwwroot\Copy_of_WebApplication2\product s.aspx.vb:133
System.Web.UI.WebControls.DataGridCommandEventHand ler.Invoke(Object
source, DataGridCommandEventArgs e) +0
System.Web.UI.WebControls.DataGrid.OnItemCommand(D ataGridCommandEventArgs
e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs
e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)

System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.Rai
sePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain() +1277

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573
____________________________________

This is the code:

Public Class products
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
________________________
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
con.Open()
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End If
End Sub
_____________________
Sub Edit(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles
dg.ItemCommand
con.Open()
dg.EditItemIndex = e.Item.ItemIndex
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End Sub
_____________________
Sub Cancel(ByVal Source As Object, ByVal E As DataGridCommandEventArgs)
Handles dg.ItemCommand
con.Open()
dg.EditItemIndex = -1
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End Sub
_____________________
Sub Update(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles
dg.ItemCommand
con.Open()
Dim txtDescr As TextBox = e.Item.Cells(2).Controls(0)
Dim txtPrice As TextBox = e.Item.Cells(3).Controls(0)
Dim strProdID As String = e.Item.Cells(1).Text
Dim strDescr As String = txtDescr.Text
Dim strPrice As String = txtPrice.Text
cmd.CommandText = "update product set description = '" & strDescr & "',
price = '" & strPrice & "' where productid = '" & strProdID & "'"
cmd.ExecuteNonQuery()
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End Sub
_____________________
End Class
Thank You.
Catalin
Nov 17 '05 #1
3 1341
"Catalin Porancea" <cp*******@midwestern.net> wrote in message
news:#x**************@TK2MSFTNGP12.phx.gbl...
Line 131: Sub dgUpdate(ByVal s As Object, ByVal e As
DataGridCommandEventArgs) Handles dg.ItemCommand
Line 132: con.Open()
Line 133: Dim txtDescr As TextBox = e.Item.Cells(1).Controls(0)
Line 134: Dim txtPrice As TextBox = e.Item.Cells(2).Controls(0)
Line 135: Dim strProdID As String = e.Item.Cells(1).Text
This code doesn't match this code:
Sub Update(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles
dg.ItemCommand
con.Open()
Dim txtDescr As TextBox = e.Item.Cells(2).Controls(0)
Dim txtPrice As TextBox = e.Item.Cells(3).Controls(0)
Dim strProdID As String = e.Item.Cells(1).Text

Are you using the most recent build?

--
[[((hillarie))]]

To reply by email, remove ".SPAMBLOCK" from email address
Nov 17 '05 #2
My mistake, I changed the code afterwards but I had the error page still
open when I copied it.
I made some progress though. This is the new code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
con.Open()
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End If
End Sub
______________________
Sub Edit(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles
dg.ItemCommand
con.Open()
dg.EditItemIndex = e.Item.ItemIndex
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End Sub
_____________________
Sub Cancel(ByVal Source As Object, ByVal E As DataGridCommandEventArgs)
Handles dg.ItemCommand
con.Open()
da.Fill(Ds_prodcat)
dg.EditItemIndex = -1
dg.DataBind()
con.Close()
End Sub
_____________________
Sub Update(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles
dg.ItemCommand
con.Open()
Dim strProdID As String = e.Item.Cells(1).Text
Dim strDescr As String = e.Item.Cells(2).Text
Dim strPrice As String = e.Item.Cells(3).Text
cmd.CommandText = "update product set description = '" & strDescr & "',
price = convert(money,replace('" & strPrice & "','$','')) where productid =
'" & strProdID & "'"
cmd.ExecuteNonQuery()
dg.EditItemIndex = -1
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End Sub
__________________

Now, I don't get that error anymore and the data grid goes into edit mode.
However, Cancel doesn't exit the edit mode. Also, Edit and Cancel trigger
the update command.

Can you help with this?

Thank you

--
Catalin Porancea
"H Branyan" <hb****************@merc.mercer.edu> wrote in message
news:bo*************@ID-92475.news.uni-berlin.de...
: "Catalin Porancea" <cp*******@midwestern.net> wrote in message
: news:#x**************@TK2MSFTNGP12.phx.gbl...
:
: > Line 131: Sub dgUpdate(ByVal s As Object, ByVal e As
: > DataGridCommandEventArgs) Handles dg.ItemCommand
: > Line 132: con.Open()
: > Line 133: Dim txtDescr As TextBox = e.Item.Cells(1).Controls(0)
: > Line 134: Dim txtPrice As TextBox = e.Item.Cells(2).Controls(0)
: > Line 135: Dim strProdID As String = e.Item.Cells(1).Text
:
: This code doesn't match this code:
:
: > Sub Update(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
Handles
: > dg.ItemCommand
: > con.Open()
: > Dim txtDescr As TextBox = e.Item.Cells(2).Controls(0)
: > Dim txtPrice As TextBox = e.Item.Cells(3).Controls(0)
: > Dim strProdID As String = e.Item.Cells(1).Text
:
:
: Are you using the most recent build?
:
: --
: [[((hillarie))]]
:
: To reply by email, remove ".SPAMBLOCK" from email address
:
:
Nov 17 '05 #3
Where did you set the DataSource of the grid?

L.L.
"Catalin Porancea" <cp*******@midwestern.net> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
My mistake, I changed the code afterwards but I had the error page still
open when I copied it.
I made some progress though. This is the new code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
con.Open()
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End If
End Sub
______________________
Sub Edit(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles
dg.ItemCommand
con.Open()
dg.EditItemIndex = e.Item.ItemIndex
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End Sub
_____________________
Sub Cancel(ByVal Source As Object, ByVal E As DataGridCommandEventArgs)
Handles dg.ItemCommand
con.Open()
da.Fill(Ds_prodcat)
dg.EditItemIndex = -1
dg.DataBind()
con.Close()
End Sub
_____________________
Sub Update(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles
dg.ItemCommand
con.Open()
Dim strProdID As String = e.Item.Cells(1).Text
Dim strDescr As String = e.Item.Cells(2).Text
Dim strPrice As String = e.Item.Cells(3).Text
cmd.CommandText = "update product set description = '" & strDescr & "',
price = convert(money,replace('" & strPrice & "','$','')) where productid = '" & strProdID & "'"
cmd.ExecuteNonQuery()
dg.EditItemIndex = -1
da.Fill(Ds_prodcat)
dg.DataBind()
con.Close()
End Sub
__________________

Now, I don't get that error anymore and the data grid goes into edit mode.
However, Cancel doesn't exit the edit mode. Also, Edit and Cancel trigger
the update command.

Can you help with this?

Thank you

--
Catalin Porancea
"H Branyan" <hb****************@merc.mercer.edu> wrote in message
news:bo*************@ID-92475.news.uni-berlin.de...
: "Catalin Porancea" <cp*******@midwestern.net> wrote in message
: news:#x**************@TK2MSFTNGP12.phx.gbl...
:
: > Line 131: Sub dgUpdate(ByVal s As Object, ByVal e As
: > DataGridCommandEventArgs) Handles dg.ItemCommand
: > Line 132: con.Open()
: > Line 133: Dim txtDescr As TextBox = e.Item.Cells(1).Controls(0)
: > Line 134: Dim txtPrice As TextBox = e.Item.Cells(2).Controls(0)
: > Line 135: Dim strProdID As String = e.Item.Cells(1).Text
:
: This code doesn't match this code:
:
: > Sub Update(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
Handles
: > dg.ItemCommand
: > con.Open()
: > Dim txtDescr As TextBox = e.Item.Cells(2).Controls(0)
: > Dim txtPrice As TextBox = e.Item.Cells(3).Controls(0)
: > Dim strProdID As String = e.Item.Cells(1).Text
:
:
: Are you using the most recent build?
:
: --
: [[((hillarie))]]
:
: To reply by email, remove ".SPAMBLOCK" from email address
:
:

Nov 17 '05 #4

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

Similar topics

3
by: Jim J | last post by:
I have been trying to find some kind of authentication method or script (PHP/perl/javascript or other) to achieve the following, with no luck. Say there are 100 files at a site. A person can...
0
by: GregD | last post by:
Our recent director of IT for the City I work for is trying to get some traction in the arena of collaborative programming to replace applications like real estate tax assessment, treasurer tax...
3
by: Peter Row | last post by:
Hi, I know this may be a bit off topic since it is really a Teechart.net issue but I am at my wits end, a total hair pulling to baldness moment. I have a windows application that uses Teechart...
6
by: Edward | last post by:
hi, everyone, I've found many examples of OWC chart, but all are VB version, when I tried to transform it into C#, compiler told me, "cannot find ChartSpace in OWC", while the same class can...
5
by: clintonG | last post by:
Neither MSDN code examples nor will function. Has anybody figured out how to use the 2.0 classes, methods and properties to dynamically create HTML in the HTML <head> element? I've burned...
12
by: Terry Olsen | last post by:
VB.NET doesn't seem to go over very well with the recreational users out in inet land. I've got a few "free" programs that I put out for people to use, and I get emails like "it'd be a nice...
4
by: Henry | last post by:
Does anybody have a real-world sample of buiding a treeview control using data from database tables? All the sample code I have found either builds the treeview manually or uses a file directory...
12
by: Ashu | last post by:
can anybody tell me the reason why following code is not working? int *funct() { int p=10; return &p; }
1
by: donbock | last post by:
I develop embedded software for avionics. It is not unheard of for the software we develop to be used for 20+ years and to be ported to several different platforms over the years (a real example:...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.