Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   FormView - FindControl (http://www.velocityreviews.com/forums/t120372-formview-findcontrol.html)

Paul Aspinall 02-25-2006 09:46 AM

FormView - FindControl
 
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



Patrick.O.Ige 02-25-2006 11:10 AM

Re: FormView - FindControl
 
Paul where are you doing that?
Patrick
**It seems it can't find the control


"Paul Aspinall" <paul@aspy.co.uk> wrote in message
news:UHVLf.54378$Q22.3024@fe1.news.blueyonder.co.u k...
> 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
>
>




Paul Aspinall 02-25-2006 01:27 PM

Re: FormView - FindControl
 
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

"Patrick.O.Ige" <naijacoder@hotmail.com> wrote in message
news:%23PR6jwfOGHA.1088@tk2msftngp13.phx.gbl...
> Paul where are you doing that?
> Patrick
> **It seems it can't find the control
>
>
> "Paul Aspinall" <paul@aspy.co.uk> wrote in message
> news:UHVLf.54378$Q22.3024@fe1.news.blueyonder.co.u k...
>> 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
>>
>>

>
>




chris 02-25-2006 02:41 PM

Re: FormView - FindControl
 
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


Paul Aspinall 02-25-2006 03:57 PM

Re: FormView - FindControl
 
Doh - Fixed it...

Thanks anyway

Paul

"Paul Aspinall" <paul@aspy.co.uk> wrote in message
news:lXYLf.69245$YJ4.30326@fe2.news.blueyonder.co. uk...
> 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
>
> "Patrick.O.Ige" <naijacoder@hotmail.com> wrote in message
> news:%23PR6jwfOGHA.1088@tk2msftngp13.phx.gbl...
>> Paul where are you doing that?
>> Patrick
>> **It seems it can't find the control
>>
>>
>> "Paul Aspinall" <paul@aspy.co.uk> wrote in message
>> news:UHVLf.54378$Q22.3024@fe1.news.blueyonder.co.u k...
>>> 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
>>>
>>>

>>
>>

>
>




Nick 02-25-2006 09:19 PM

Re: FormView - FindControl
 
What was it Paul?

I get the same error.

Cheers,

Nick

"Paul Aspinall" <paul@aspy.co.uk> wrote in message
news:k7%Lf.69977$YJ4.59568@fe2.news.blueyonder.co. uk...
> Doh - Fixed it...
>
> Thanks anyway
>
> Paul
>
> "Paul Aspinall" <paul@aspy.co.uk> wrote in message
> news:lXYLf.69245$YJ4.30326@fe2.news.blueyonder.co. uk...
>> 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
>>
>> "Patrick.O.Ige" <naijacoder@hotmail.com> wrote in message
>> news:%23PR6jwfOGHA.1088@tk2msftngp13.phx.gbl...
>>> Paul where are you doing that?
>>> Patrick
>>> **It seems it can't find the control
>>>
>>>
>>> "Paul Aspinall" <paul@aspy.co.uk> wrote in message
>>> news:UHVLf.54378$Q22.3024@fe1.news.blueyonder.co.u k...
>>>> 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
>>>>
>>>>
>>>
>>>

>>
>>

>
>




Paul Aspinall 02-26-2006 05:15 PM

Re: FormView - FindControl
 
Hi Nick,

I've emailed you.

Cheers
"Nick" <nick.rawlins@gmail.com> wrote in message
news:O%23t0aElOGHA.720@TK2MSFTNGP14.phx.gbl...
> What was it Paul?
>
> I get the same error.
>
> Cheers,
>
> Nick
>
> "Paul Aspinall" <paul@aspy.co.uk> wrote in message
> news:k7%Lf.69977$YJ4.59568@fe2.news.blueyonder.co. uk...
>> Doh - Fixed it...
>>
>> Thanks anyway
>>
>> Paul
>>
>> "Paul Aspinall" <paul@aspy.co.uk> wrote in message
>> news:lXYLf.69245$YJ4.30326@fe2.news.blueyonder.co. uk...
>>> 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
>>>
>>> "Patrick.O.Ige" <naijacoder@hotmail.com> wrote in message
>>> news:%23PR6jwfOGHA.1088@tk2msftngp13.phx.gbl...
>>>> Paul where are you doing that?
>>>> Patrick
>>>> **It seems it can't find the control
>>>>
>>>>
>>>> "Paul Aspinall" <paul@aspy.co.uk> wrote in message
>>>> news:UHVLf.54378$Q22.3024@fe1.news.blueyonder.co.u k...
>>>>> 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
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>




cdutoit 04-03-2007 04:14 PM

Hi,

I'm having the same problem. Could you post the solution here?

Thanks
Chris

nick5454 02-04-2008 04:41 PM

And then answer is...

FormView1.Row.FindControl("XXX");

For those of you who are wondering. Or simply if you find an answer post it, don't hide it

deverdits 05-11-2008 02:30 AM

I'm having the same problem but usin VB, would anyone have a solution to this in VB? I've never done anything in C# so I don't know how to even start converting it.

Much appreciated
John.


All times are GMT. The time now is 01:23 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57