Solved

how do i prepopulate FormView textbox

Posted on 2006-10-29
1
1,084 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 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