FormView - FindControl

P

Paul Aspinall

Hi
I'm having trouble trying to use FindControl with a FormView, but can't seem
to find what I'm doing wrong....

I have a TextBox in my ItemTemplate, and I want to assign a value to it, in
code...

I'm trying:

((TextBox)FormView1.FindControl("TextBox1")).Text = "Sample value";



The error reported is 'Object reference not set to an instance of an
object.'



Any ideas?



Thanks
 
P

Paul Aspinall

I've tried it in a few places, prerender, load, databinding etc.

No joy anywhere.

Has anyone actually managed to do this in C#??

Thanks
 
C

chris

This may help.

protected override void OnInit(EventArgs e)
{
FormView1.ItemCreated += new
EventHandler(FormView1_ItemCreated);
base.OnInit(e);
}

void FormView1_ItemCreated(object sender, EventArgs e)
{
TextBox t = (TextBox)FormView1.Row.FindControl("TextBox1");
t.Text = "foo";
}

Chris
 
P

Paul Aspinall

Doh - Fixed it...

Thanks anyway

Paul

Paul Aspinall said:
I've tried it in a few places, prerender, load, databinding etc.

No joy anywhere.

Has anyone actually managed to do this in C#??

Thanks
 

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

Top