access controls inside formview inside loginview

W

wikkiwikkiwaa

hello,

i am trying to access controls inside my formview1 nested inside
loginview1. you cannot access the formview1 unless you are properly
logged in.

for loginview1, that seems to be fairly simple. a label control would
be:
Label label1 = (Label)loginview1.FindControl("nameoflabel");
then i get to the data that was bound to that control.

i cannot figure out how to get to the formview1 controls. the formview1
defaults to the itemtemplate, but also has a edititem and iteminsert
templates. the labels i am trying to get to inside formview1 are
ZIPLabel, ADDR1Label, and CITYLabel. i cannot seem to get the syntax to
get to them correct.

i'm also not sure at what point they have been created and that i
really have access to them. for example.

i tried to get to them through one of the events formview1_DataBound,
but they don't seem to exist yet.

i'm missing something fundamental here and i'm starting to get
frustrated. any help would be appreciated.

thank you for your time
 
G

Guest

So long as the controls in the FormView are named uniquely within the
formview, not just within the Template then it should be no problem, so just
have to call two sets of FindControl

e.g. to access a textbox that is within the formview:

FormView MyFormView = (FormView)LoginView1.FindControl("FormViewID~");

TextBox MyTextBox = (TextBox)MyFormView.FindControl("TextBoxID");

MyTextBox.Text = "Some Words";

However if you have a text box in the insert item template and the edit item
template with the same ID then it will generate an error. Also if you try to
retreive a control from the edit item template and the FormView is not in
edit mode then you will probably get the object reference not set to instance
of an object error.
 
W

wikkiwikkiwaa

thank you so much for your help. appreciate you taking the time to
check out my problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top