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

M

Michael

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-------------
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top