Using FindControl to locate a textbox inside Listview

hsmith825
hsmith825 used Ask the Experts™
on
I have a Textbox inside a  Listview.  The Listvioew is inside a Tab and an update pannel.  The code is attached.  Anytime I use this snipped I get a null value.  

Any help in Visual Vasic is appreciated.

Thanks!!!

hsmith825
<asp:ListView ID="Preference" runat="server" DataSourceID="SqlprefDataSource2" 
        DataKeyNames="Reviewer_UserID">
<ItemTemplate>
<asp:TextBox ID="Type_Review" CssClass="cnotesl" runat="server" Text='<%# Eval("Type_Review") %>' ReadOnly="True">
                  </asp:TextBox>
 
The code behind is:
Dim saccess As TextBox = Preference.FindControl("Type_Review")

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
you need to enumerate throught the control in the template first

To find the control use this code.

Private sub findCon
dim objText as textbox

for i = 0 to Preference.items.count - 2
objText= directcast(preference.item(i).findcontrol("Type_Review"),textbox)
Next


End

Author

Commented:
Hi Miketayl,
I had to make one change to get it to work.  I used:
objText= directcast(preference.items.item(i).findcontrol("Type_Review"),textbox)

Thanks for the solution
hsmith825

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial