Solved

how do i prepopulate FormView textbox

Posted on 2006-10-29
1
1,080 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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