Keep the Bind while setting the text of a textbox in FormView

Discussion in 'ASP .Net' started by Michael, Jun 2, 2009.

  1. Michael

    Michael Guest

    I have one textbox in a FormView 'Insert Template' and it is bound to the
    'FirstName' in a database. What I am trying to do is set the text to equal
    the text from a hidden field named hiddenFirstName and not lose its binding
    to the 'FirstName' field in the database. I then want to be able to insert
    it into the database after clicking the 'Insert' text.

    The code to assign the hidden value to the FormView's 'FirstName' textbox is
    below. I've tried two different methods to accomplish the task and both have
    resulted in errors. Below that is the code for the FormView.

    Thanks

    ---------Beginning of Script Code-------------

    <script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    my_hiddenFirstName.Value = Request.Form("hiddenFirstName")

    (Method 1) - > FirstNameTextBox.Text = my_hiddenFirstName.Value ----->
    (This generates an error)

    (Method 1) - > (TextBox)FormView1.FindControl(FirstNameTextBox).Text =
    my_hiddenFirstName.Value -----> (This generates an error)

    End Sub

    </script>

    ---------End of Script Code-------------



    ---------Beginning of FormView Code-------------

    <asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"

    DataSourceID="AccessDataSource1" DefaultMode="Insert" AllowPaging="True">

    <asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"

    DataSourceID="AccessDataSource1" DefaultMode="Insert" AllowPaging="True">

    <InsertItemTemplate>

    FirstName:

    <asp:TextBox ID="FirstNameTextBox" runat="server"

    Text='<%# Bind("FirstName") %>' />

    <br />

    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"

    CommandName="Insert" Text="Insert" />

    &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"

    CausesValidation="False" CommandName="Cancel" Text="Cancel" />

    </InsertItemTemplate>

    </asp:FormView>

    <asp:AccessDataSource ID="AccessDataSource1" runat="server"

    DataFile="~/App_Data/customers.mdb"

    InsertCommand="INSERT INTO [Customers] ([FirstName], [ID]) VALUES (?, ?)" >

    <InsertParameters>

    <asp:parameter Name="FirstName" Type="String" />

    <asp:parameter Name="ID" Type="Int32" />

    </InsertParameters>

    </asp:AccessDataSource>

    ---------End of FormView Code-------------
     
    Michael, Jun 2, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mr2_93
    Replies:
    1
    Views:
    3,625
    mr2_93
    Oct 2, 2005
  2. =?Utf-8?B?ZnJhbms=?=

    Keep the format of MultiLine TextBox.Text

    =?Utf-8?B?ZnJhbms=?=, Aug 16, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    623
    =?Utf-8?B?ZnJhbms=?=
    Aug 16, 2006
  3. Replies:
    0
    Views:
    598
  4. frank

    Keep the format of MultiLine TextBox.Text

    frank, Aug 15, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    144
    frank
    Aug 15, 2006
  5. hisan
    Replies:
    1
    Views:
    1,366
    Dan Stromberg
    Jun 25, 2012
Loading...

Share This Page