Hey all,
I have a problem with the update using a datagrid control in Visual Studio .Net ... here is my code:
Code:
Private Sub MyDG_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles MyDG.EditCommand
Me.MyDG.EditItemIndex = e.Item.ItemIndex
MyDG.DataBind()
Dim key As String = MyDG.DataKeys(e.Item.ItemIndex).ToString
Dim catName, CatImage, CatThumb, CatDesc As String
Dim tb As TextBox
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
catName = tb.Text
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
CatImage = tb.Text
tb = CType(e.Item.Cells(4).Controls(0), TextBox)
CatThumb = tb.Text
tb = CType(e.Item.Cells(5).Controls(0), TextBox)
CatDesc = tb.Text
Dim r As MyDS.CategoriesRow
r = MyDS1.Categories.FindByCategoryID(key)
r.CategoryName = catName
r.CatImage = CatImage
r.Description = CatDesc
r.Thumbnail = CatThumb
SqlDataAdapter1.Update(MyDS1)
Me.MyDG.EditItemIndex = -1
MyDG.DataBind()
End Sub
When i run, i get the following error: Specified argument was out of the range of valid values. Parameter name: index
This line get marked in red:
Line 146: tb = CType(e.Item.Cells(2).Controls(1), TextBox)
It seems a problem with the Controls or the Cells index, but there is no mistake or so i belive. Any help?
Regards,
Hany