Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > FormView - FindControl

Reply
Thread Tools

FormView - FindControl

 
 
Paul Aspinall
Guest
Posts: n/a
 
      02-25-2006
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


 
Reply With Quote
 
 
 
 
Patrick.O.Ige
Guest
Posts: n/a
 
      02-25-2006
Paul where are you doing that?
Patrick
**It seems it can't find the control


"Paul Aspinall" <> wrote in message
news:UHVLf.54378$ 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
>
>



 
Reply With Quote
 
 
 
 
Paul Aspinall
Guest
Posts: n/a
 
      02-25-2006
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" <> wrote in message
news:%...
> Paul where are you doing that?
> Patrick
> **It seems it can't find the control
>
>
> "Paul Aspinall" <> wrote in message
> news:UHVLf.54378$ 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
>>
>>

>
>



 
Reply With Quote
 
chris
Guest
Posts: n/a
 
      02-25-2006
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

 
Reply With Quote
 
Paul Aspinall
Guest
Posts: n/a
 
      02-25-2006
Doh - Fixed it...

Thanks anyway

Paul

"Paul Aspinall" <> wrote in message
news:lXYLf.69245$. 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" <> wrote in message
> news:%...
>> Paul where are you doing that?
>> Patrick
>> **It seems it can't find the control
>>
>>
>> "Paul Aspinall" <> wrote in message
>> news:UHVLf.54378$ 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
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Nick
Guest
Posts: n/a
 
      02-25-2006
What was it Paul?

I get the same error.

Cheers,

Nick

"Paul Aspinall" <> wrote in message
news:k7%Lf.69977$. uk...
> Doh - Fixed it...
>
> Thanks anyway
>
> Paul
>
> "Paul Aspinall" <> wrote in message
> news:lXYLf.69245$. 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" <> wrote in message
>> news:%...
>>> Paul where are you doing that?
>>> Patrick
>>> **It seems it can't find the control
>>>
>>>
>>> "Paul Aspinall" <> wrote in message
>>> news:UHVLf.54378$ 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
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Paul Aspinall
Guest
Posts: n/a
 
      02-26-2006
Hi Nick,

I've emailed you.

Cheers
"Nick" <> wrote in message
news:O%...
> What was it Paul?
>
> I get the same error.
>
> Cheers,
>
> Nick
>
> "Paul Aspinall" <> wrote in message
> news:k7%Lf.69977$. uk...
>> Doh - Fixed it...
>>
>> Thanks anyway
>>
>> Paul
>>
>> "Paul Aspinall" <> wrote in message
>> news:lXYLf.69245$. 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" <> wrote in message
>>> news:%...
>>>> Paul where are you doing that?
>>>> Patrick
>>>> **It seems it can't find the control
>>>>
>>>>
>>>> "Paul Aspinall" <> wrote in message
>>>> news:UHVLf.54378$ 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
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
cdutoit cdutoit is offline
Junior Member
Join Date: Apr 2007
Posts: 1
 
      04-03-2007
Hi,

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

Thanks
Chris
 
Reply With Quote
 
nick5454 nick5454 is offline
Junior Member
Join Date: Feb 2008
Posts: 2
 
      02-04-2008
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
 
Reply With Quote
 
deverdits deverdits is offline
Junior Member
Join Date: May 2008
Posts: 2
 
      05-11-2008
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FindControl in FormView Edit Template SteveT ASP .Net 1 06-07-2007 06:47 PM
findcontrol in a formview Mr. SweatyFinger ASP .Net 0 12-01-2006 02:46 AM
Equating one formview to another ?? Dynamic type code? Findcontrol? jobs ASP .Net 0 11-07-2006 05:08 PM
Formview FindControl conversion to c# sck10 ASP .Net 2 08-28-2006 10:56 PM
FindControl in FormView Zarn Bou via DotNetMonster.com ASP .Net 0 03-16-2005 12:06 AM



Advertisments
 



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