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 | | | | re: Can anybody help with this code?
"Catalin Porancea" <cporancea@midwestern.net> wrote in message
news:#xon#aJpDHA.2312@TK2MSFTNGP12.phx.gbl...
[color=blue]
> 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[/color]
This code doesn't match this code:
[color=blue]
> 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[/color]
Are you using the most recent build?
--
[[((hillarie))]]
To reply by email, remove ".SPAMBLOCK" from email address | | | | re: Can anybody help with this code?
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" <hbranyan.SPAMBLOCK@merc.mercer.edu> wrote in message
news:boe6kd$1dlm2g$1@ID-92475.news.uni-berlin.de...
: "Catalin Porancea" <cporancea@midwestern.net> wrote in message
: news:#xon#aJpDHA.2312@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
:
: | | | | re: Can anybody help with this code?
Where did you set the DataSource of the grid?
L.L.
"Catalin Porancea" <cporancea@midwestern.net> wrote in message
news:%23Y4sCvJpDHA.424@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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[/color]
=[color=blue]
> '" & 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" <hbranyan.SPAMBLOCK@merc.mercer.edu> wrote in message
> news:boe6kd$1dlm2g$1@ID-92475.news.uni-berlin.de...
> : "Catalin Porancea" <cporancea@midwestern.net> wrote in message
> : news:#xon#aJpDHA.2312@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
> :
> :
>
>[/color] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,439 network members.
|