Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone!

I have trouble in this error wherein i didnt understand how i will adjust this command..please help me and thank you in advance...

VB
Dim Item As ListViewItem = DirectCast(lvsummary.Items(0), ListViewItem)
        Dim txtid As TextBox = DirectCast(Item.FindControl("idTextbox"), TextBox)


in which the error in this line : Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

i already add the parameter on this command:
txtid.Text = cmdtest.Parameters("@id").Value
Posted

You have only one index here, 0. Therefore, lvsummary.Items element count it zero. Before accessing any array or collection with zero-based indexing, make sure there is at least one element.

—SA
 
Share this answer
 
This exception is obvious. You are trying to access a member of an collection which does not exist. For e.g. your ListView is not having any item or it is null but still if you are trying to access the ListItem. This will throw an error. Try stepping through your code and check the value of lvsummary.
Try this:
VB
Dim Item As ListViewItem = CType(lvsummary.Items(0), ListViewItem)
If Not Item.FindControl("idTextbox") Is Nothing
    Dim txtid As TextBox = CType(Item.FindControl("idTextbox"), TextBox)
End If



--Amit
 
Share this answer
 
v2
Comments
Member 10033107 5-Jun-13 2:02am    
Hi Amit thanks for the reply,..
Lvsummary is the a listview id of my listviewtable wherein i want to call a value i posted for id..
Member 10033107 5-Jun-13 2:02am    
and by the way what is CType that you call in your comment?? thanks
_Amy 5-Jun-13 2:04am    
CType returns the result of explicitly converting an expression to a specified data type, object, structure, class, or interface.
Member 10033107 5-Jun-13 2:08am    
okay thank you i will try this command thanks again
Member 10033107 5-Jun-13 2:18am    
amit, can you give me an example for this command because it expect end if statement

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900