|
-
Apr 1st, 2003, 08:29 PM
#1
Thread Starter
Member
Simple .Net Question
I'm getting this error in .Net
"Specified argument was out of the range of valid values. Parameter name: index"
Then it point s to this:
Line 186: Dim tb As TextBox
Line 187:
<B>Line 188: tb = CType(e.Item.Cells(1).Controls(1), TextBox)</B>
Line 189: Addr = tb.Text
Line 190:
I just want to know which part of that bold statement I should be paying attention to with regards to the INDEX error. I'm VERY new to .Net and I haven't got the hang of debugging yet. Thanks as always!
HWOOD
-
Apr 1st, 2003, 08:56 PM
#2
Addicted Member
the error mean that it can't find what your looking for within the range you specified becuase there is no data in that range.
Double check the range you have set.
Hopefully that helps
-
Apr 1st, 2003, 09:15 PM
#3
The .Cells(1) and .Controls(1) are what you should be looking at. Remember that everything is 0 based in .Net, so try using .Cells(0) and .Controls(0) for the first item in the set.
-
Apr 1st, 2003, 10:26 PM
#4
Thread Starter
Member
When I set them both to ZERO, it says SPECIFIED CAST IS INVALID. I'm seriously about to throw my computer out the window and start collecting trash as an occupation. Here's all the code I have... hopefully one of you can see what I'm doing wrong. .. I'm getting another beer...
Maybe I'm not initializing a connection or something... I'm ready to give up....
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
SqlDataAdapter1.Fill(ListingsDS1)
If Not IsPostBack Then
MyDG.DataBind()
End If
End Sub
Private Sub MyDG_SortCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs)
DataView1.Sort = e.SortExpression
MyDG.DataBind()
End Sub
Private Sub MyDG_PageIndexchanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
MyDG.CurrentPageIndex = e.NewPageIndex
MyDG.DataBind()
End Sub
Private Sub MyDG_CancelCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
MyDG.EditItemIndex = -1
MyDG.DataBind()
End Sub
Private Sub MyDG_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles MyDG.EditCommand
MyDG.EditItemIndex = e.Item.ItemIndex
MyDG.DataBind()
Dim Key As String = MyDG.DataKeys(e.Item.ItemIndex).ToString
Dim Name, Address, Phone As String
Dim tb As TextBox
tb = CType(e.Item.Cells(0).Controls(0), TextBox)
Name = tb.Text
tb = CType(e.Item.Cells(1).Controls(0), TextBox)
Address = tb.Text
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
Phone = tb.Text
Dim r As ListingsDS.ListingsRow
r = ListingsDS1.Listings.FindByListNo(Key)
r.Data1= Name
r.Data2 = Address
r.Data3 = Phone
SqlDataAdapter1.Update(ListingsDS1)
MyDG.EditItemIndex = -1
MyDG.DataBind()
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|