Solved

how do i prepopulate FormView textbox

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

Technology Partners: 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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 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