cajunworks
asked on
Asp .net CType(e.Item.Cells(2).Controls(0), TextBox) ----> Error: Out of bound
I am trying to put a edit button in the DataGrid, so when clicked would display a textbox to edit the record.
Here is the code:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ----
Private Sub MyDG_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls. DataGridCo mmandEvent Args) Handles MyDG.EditCommand
MyDG.EditItemIndex = e.Item.ItemIndex()
MyDG.DataBind()
Dim key As String = MyDG.DataKeys(e.Item.ItemI ndex).ToSt ring
Dim CatName, CatImage, CatThumb, CatDesc As String
Dim tb As TextBox
tb = CType(e.Item.Cells(2).Cont rols(0), TextBox) 'Here is where I am getting ERROR
CatName = tb.Text
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
It gives me following ERROR:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
Specified argument was out of the range of valid values. Parameter name: index
Line 149: tb = CType(e.Item.Cells(2).Cont rols(0), TextBox)
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
I Debug the program and try to get the values and it gave me following result:
?e.item.cells.count ----------------------> 6
?e.item.cells.controls.cou nt -------------> 0 'I think here is the problem because it is zero
But I don't know what does it mean and how would I solve it.
Please Help !!!
Here is the code:
--------------------------
Private Sub MyDG_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.
MyDG.EditItemIndex = e.Item.ItemIndex()
MyDG.DataBind()
Dim key As String = MyDG.DataKeys(e.Item.ItemI
Dim CatName, CatImage, CatThumb, CatDesc As String
Dim tb As TextBox
tb = CType(e.Item.Cells(2).Cont
CatName = tb.Text
--------------------------
It gives me following ERROR:
--------------------------
Specified argument was out of the range of valid values. Parameter name: index
Line 149: tb = CType(e.Item.Cells(2).Cont
--------------------------
I Debug the program and try to get the values and it gave me following result:
?e.item.cells.count ----------------------> 6
?e.item.cells.controls.cou
But I don't know what does it mean and how would I solve it.
Please Help !!!
Try something like this:
tb = CType(e.Item.Cells(2).Cell s(0).Contr ols(0), TextBox)
So access cell 0 inside cell 2.
tb = CType(e.Item.Cells(2).Cell
So access cell 0 inside cell 2.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what X_COM said is correct.. you can use the <EDITITEM TEMPLATE> to put a textbox while editing..its great
Nalini
Nalini
The problem is realy in e.item.cells.controls.coun
B..G