C
Catalin Porancea
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\products.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\products.aspx.vb:133
System.Web.UI.WebControls.DataGridCommandEventHandler.Invoke(Object
source, DataGridCommandEventArgs e) +0
System.Web.UI.WebControls.DataGrid.OnItemCommand(DataGridCommandEventArgs
e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs
e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Rai
sePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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
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\products.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\products.aspx.vb:133
System.Web.UI.WebControls.DataGridCommandEventHandler.Invoke(Object
source, DataGridCommandEventArgs e) +0
System.Web.UI.WebControls.DataGrid.OnItemCommand(DataGridCommandEventArgs
e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs
e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Rai
sePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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