Solved

how do i prepopulate FormView textbox

Posted on 2006-10-29
1
1,078 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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

17 Experts available now in Live!

Get 1:1 Help Now