Avatar of Carla Romere
Carla RomereFlag for United States of America

asked on 

Populate TextBox outside FormView with Values of fields inside FormView

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

ASP.NETC#

Avatar of undefined
Last Comment
Carla Romere
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Try this

HTH

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

Open in new window

Avatar of Carla Romere
Carla Romere
Flag of United States of America image

ASKER

Now I get this error:

CS0030: Cannot convert type 'updpm' to 'System.Web.UI.WebControls.TextBox'
ASKER CERTIFIED SOLUTION
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Carla Romere
Carla Romere
Flag of United States of America image

ASKER

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.
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

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

SOLUTION
Avatar of Carla Romere
Carla Romere
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Carla Romere
Carla Romere
Flag of United States of America image

ASKER

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!
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo