![]() |
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 |
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 > > |
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 >> >> > > |
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 |
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 >>> >>> >> >> > > |
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 >>>> >>>> >>> >>> >> >> > > |
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 >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > |
Hi,
I'm having the same problem. Could you post the solution here? Thanks Chris |
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 |
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.