How do I Declare a text box

  • Thread starter Thread starter Mo
  • Start date Start date
M

Mo

Hi,

I am trying to grab the text value of a text box in a formview. I know
how to do it the long way using findcontrol but I have a few textboxes
in the control and I am looking for a one liner to grab this value. I
am looking for something like this code:

string[] MyArray = new string[10];
MyArray[0] = (TextBox)FormView6.FindControl("FirstTextBox").Text;

But obviously this is not the right format to declare it! Any body have
an idea how to declare this value?

Thanks,
Mo
 
Ok Google just moved their beta to live and it isn't working in Opera,
so as I'm typing blind, bear with me :)

I think

MyArray[0] =(TextBox)(FormView6.FindControl("FirstTextBox")).Text;

should work, you need to cast the entire expression that refers to the
textbox.
 
MyArray[0] =(TextBox)(FormView6.FindControl("FirstTextBox")).Text;

Haven't you missed a bracket off...?

MyArray[0] = ((TextBox)(FormView6.FindControl("FirstTextBox")).Text;
 
Yep, sorry I was having browser issues (and probably morning brain
issues)

I meant:

MyArray[0] = ((TextBox)FormView6.FindControl("FirstTextBox")).Text;

So FindControl refers to a method on FormView6 that returns a Control
but the reason it went wrong is because .Text refers to a property on a
TextBox. By enclosing the cast and the function in brackets we force
the order of evaluation.

This would also work

TextBox t = (TextBox)FormView6.FindControl("FirstTextBox")
MyArray[0] = t.Text;


DeveloperX said:
MyArray[0] =(TextBox)(FormView6.FindControl("FirstTextBox")).Text;Haven't you missed a bracket off...?

MyArray[0] = ((TextBox)(FormView6.FindControl("FirstTextBox")).Text;
 

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

Back
Top