Hi Everyone,
i have this listview and i need to extract the email field and name field out
i have try this but i get err each time - Object reference not set to an instance of an object.
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim text6 As TextBox = Me.ListView1.FindControl("email")
Label2.Text = text6.Text
End Sub
ThankX
ListView containing many items, you need specify the itemindex to use FindControl. Loop the ListView items then get the control using : Dim text6 As TextBox = CType(ListView1.Items(i).FindControl("email"), TextBox)
I try the following it has the same err still
Dim i As Integer
For i = i To Me.ListView1.Items.Count - 1
Dim text6 As TextBox = CType(ListView1.Items(i).FindControl("email"), TextBox)
Label2.Text = text6.Text
Next i
Thanks
Hi,
I use the following:
Dim i As Integer For i = 0 To Me.ListView1.Items.Count - 1 Dim text6 As TextBox = CType(ListView1.Items(i).FindControl("email"), TextBox) Label2.Text = text6.Text Next i
and it works well in my computer.
If you are using the paging, then it may not work, because the listView.Items.Count is set to the items on the current page only.
For more information, please try to refer to this similar thread:
http://stackoverflow.com/questions/6877943/finding-an-item-in-asp-listview-with-value-when-paging-is-enabled .
Best Regards,
Amy Peng
Where you place the button? Inside or outside ListView? If inside ListView, you can use ListView ItemCommand event.
outside
this were the code stop
Line 77: Label2.Text = text6.Text
if there is not data in the listview everything is fine no error when you click the button if there is data it failed which make me think that it is not extract one field, and the label is not able to contain all the data
????
im not using paging and all i pull is one recored at time. i try the =0 but i get the same error.
im not sure why my code does not work, if you have any ideas please share.
Thank you
p.s.
Im not sure if it will help but im running a qurey before i get the listview, user need to enter thier ID and then click on button which bring the listview with the same ID number. then when they can update the recored and submit upon submit i would like
to get the email value the enter so i can send then an email confirmation with all the data they entered.
For Each item As ListViewItem In ListView1.Items
Dim TextBoxEmail = CType(item.FindControl("TextBoxEmail"), TextBox)
Label2.Text += TextBoxEmail.Text
Next
this is crazy why it is doing that ??? can you please send me the page and code togther and i will load it here and see if it is working? thank you
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 73: For Each item As ListViewItem In ListView1.Items |
Amy you say that it is working on your computer can you please send me the test page & code you have, i can then test it on my computer and see if it is maybe issue with my laptop. ty
Do you have textbox with id= "email" in ListView ItemTemplate?
i CAN NOT BELIEVE IT, HOW the F... it change, it is "emaillable" thanks for meantion it. i appreciate your help
Thank you Thank you Thank you
沒有留言:
張貼留言