[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Populate TextBox outside FormView with Values of fields inside FormView

Posted on 2011-10-07
7
Medium Priority
?
760 Views
Last Modified: 2012-05-12
I have a table that I can't update via a normal FormView (Insert, Update, Edit) process. So I have a FormView that displays the information and I want to populate textboxes outside the FormView with the information in the formview in preparation for a table update done through a stored procedure.

The first code works fine to display the values of the two search textboxes.

The second code is where I'm trying to populate a textbox outside the formview with the current value inside the formview. I get this error:

CS0030: Cannot convert type 'string' to 'System.Web.UI.WebControls.TextBox'
So I took out the "ToString()" part and get this error:

CS0029: Cannot implicitly convert type 'System.Web.UI.WebControls.TextBox' to 'string'

I simply want to populate the textboxes outside the formview with the values of the texboxes inside the formview so they can modify the ones they need to but not have to retype everything before they run their update. They may only want to change one field and the others stay the same. I know there's a way to do this, I'm just missing it somehow.



protected void btnShowpart_Click(object sender, EventArgs e)
    {
        FormView1.Visible = true;
        txtNewpartcode.Text = txtPartcode.Text;
        txtNewcustnbr.Text = txtCustnbr.Text;
        btnShowmodify.Visible = true;
    }

Open in new window

protected void btnShowmodify_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;
        txtNewcustpart.Text = ((TextBox)this.FormView1.FindControl("txtCurrcustpart").ToString());
    }

Open in new window

0
Comment
Question by:Carla Romere
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 36930834
Try this

HTH

Ivo Stoykov
txtNewcustpart.Text = ((TextBox)this).FormView1.FindControl("txtCurrcustpart").Text;

Open in new window

0
 

Author Comment

by:Carla Romere
ID: 36930885
Now I get this error:

CS0030: Cannot convert type 'updpm' to 'System.Web.UI.WebControls.TextBox'
0
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 2000 total points
ID: 36931422
what is type updpm?
what return ((TextBox)this).FormView1.FindControl("txtCurrcustpart")?
try debugging to see what happens in this function...

HTH

Ivo Stoykov
Debug.Print(((TextBox)this).FormView1.FindControl("txtCurrcustpart").GetType());

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Carla Romere
ID: 36931459
updpm.aspx is the name of the page itself.

Here's what I ran:


    protected void btnShowmodify_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;
       // txtNewcustpart.Text = ((TextBox)this).FormView1.FindControl("txtCurrcustpart").Text;
        Debug.Print(((TextBox)this).FormView1.FindControl("txtCurrcustpart").GetType());

    }

This is what I got:

CS0122: 'System.Configuration.Debug' is inaccessible due to its protection level

I have "using System.Configuration;" included in my code behind.
0
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 36932220
OK this is because of the ((TextBox)this) - then this is your page
try the snippet below.
shuld use System.Diagnostics instead of


HTH

Ivo Stoykov
Control ctrl = this.FormView1.FindControl("txtCurrcustpart")
System.Diagnostics.Debug.Print(ctrl.GetType().FullName);
System.Diagnostics.Debug.Print(ctrl.Text); // it this is the textbox should show the text; else - error

Open in new window

0
 

Assisted Solution

by:Carla Romere
Carla Romere earned 0 total points
ID: 36933217
I finally got this working using some code I found somewhere else. I had to declare a new variable and set that variable to the value in the FormView and THEN set my textbox equal to the new variable I created.

        TextBox Newcustpart = (TextBox)FormView1.FindControl("txtCurrcustpart");
        txtNewcustpart.Text = Newcustpart.Text;

This works beautifully except on the DropDownList in the new textboxes outside the FormView.

        TextBox Newwarehouse = (TextBox)FormView1.FindControl("txtCurrwarehouse");
        ddlNewwarehouse.SelectedValue = Newwarehouse.Text;

I ended up just making the drop down another textbox and it's working now. I would like to have it remain a drop down but couldn't figure out how to get the selected value in the dropdown to be the same as a textbox value from the formview.
0
 

Author Closing Comment

by:Carla Romere
ID: 36978193
Your suggestion got me on the right track, but I had to add a second variable in order to get it to work. Thanks for the help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question