Solved

how do i prepopulate FormView textbox

Posted on 2006-10-29
1
1,079 Views
Last Modified: 2012-08-13
Can someone show me the code to  prepopulate a textbox in a FormView Control in insert mode,  In c#.  (using  ASP 2.0 and  VWD )I have  the following code but it doesn’t work.

This is what i have:

protected void nameTextBox_TextChanged1(object sender, EventArgs e)
    {
       
        TextBox  fnam =
       (TextBox)FormView2.Row.FindControl("nameTextBox");

        fnam.Text = Label3.Text;
    }
   


 <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            DeleteCommand="DELETE FROM [tesconntes] WHERE [myid] = @myid" InsertCommand="INSERT INTO [tesconntes] ([name], [lname]) VALUES (@name, @lname)"
            SelectCommand="SELECT * FROM [tesconntes]" UpdateCommand="UPDATE [tesconntes] SET [name] = @name, [lname] = @lname WHERE [myid] = @myid">
            <DeleteParameters>
                <asp:Parameter Name="myid" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="name" Type="String" />
                <asp:Parameter Name="lname" Type="String" />
                <asp:Parameter Name="myid" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="name" Type="String" />
                <asp:Parameter Name="lname" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
0
Comment
Question by:bmanmike39
1 Comment
 
LVL 27

Accepted Solution

by:
Sammy earned 500 total points
ID: 17831065
You can do it in 2 ways
//Code
//1-Using the ItemCreated event of the formview

 void FormView2_ItemCreated(object sender, EventArgs e)
    {
        if (FormView2.CurrentMode == FormViewMode.Insert)
        {
           TextBox  fnam = (TextBox)FormView2.Row.FindControl("nameTextBox");
            if (fnam != null)
            {
                fnam.Text=Label3.Text;
            }
        }
    }

//Or
//2-Using The formview's ItemInserting

    void FormView2_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
       TextBox  fnam = (TextBox)FormView2.Row.FindControl("nameTextBox");
        if (fnam != null)
        {
           fnam.Text=Label3.Text;
        }
    }

HTH
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now