Pass Values from Formview child controls to unbound textbox

I have created a formview that is bound to a table in an Access database with an AccesDataSource object.

How do I pass the values contained in the labels in the formview to unbound textboxes outside of the formview

 

<asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource2" Width="519px" Visible =false HeaderText="Company Address" HeaderStyle-Font-Bold="true" >

<ItemTemplate>

<table style="width: 557px; height: 91px">

<tr>

<td style="width: 100px">

Address:</td>

<td style="width: 100px">

City:</td>

<td style="width: 100px">

PostalCode:</td>

</tr>

<tr>

<td style="width: 100px; height: 20px">

<asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>'></asp:Label></td>

<td style="width: 100px; height: 20px">

<asp:Label ID="CityLabel" runat="server" Text='<%# Bind("City") %>'></asp:Label></td>

<td style="width: 100px; height: 20px">

<asp:Label ID="PostalCodeLabel" runat="server" Text='<%# Bind("PostalCode") %>'></asp:Label></td>

</tr>

<tr>

<td style="width: 100px">

Country:</td>

<td style="width: 100px">

Phone:</td>

<td style="width: 100px">

Fax:</td>

</tr>

<tr>

<td style="width: 100px">

<asp:Label ID="CountryLabel" runat="server" Text='<%# Bind("Country") %>'></asp:Label></td>

<td style="width: 100px">

<asp:Label ID="PhoneLabel" runat="server" Text='<%# Bind("Phone") %>'></asp:Label></td>

<td style="width: 100px">

<asp:Label ID="FaxLabel" runat="server" Text='<%# Bind("Fax") %>'></asp:Label></td>

</tr>

</table>

</ItemTemplate>

</asp:FormView>

I want to fill unbound textboxes outside of this form with the values of the labels contained in the formview



Answer this question

Pass Values from Formview child controls to unbound textbox

  • ZezeLazo

    I have figured it out, I used:

    Dim a As String = CType(Me.FormView1.FindControl("AddressLabel"), Label).Text
    ShipAddress.Text = a
    ShipAddress.Visible = True

  • jntrobertsen

    I has the same problem, at have used hours on solvine it. But here is a C# version that works for me.

    TextBox myTextBox = ((TextBox)this.FormView1.FindControl("SomeTextBox"));

    Hope my anserwer is not to late for yor.



  • Dinesh.s

    I haven't had any success with that I have tried a few variations to no avail
    The following button event makes the unbound textboxes visible, and, I pass the text in the labels that are in the form view to these.

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    lblShippingInfo.Visible = True
    lblShipName.Visible = True
    lblShipAddress.Visible = True
    lblCity.Visible = True
    ShipName.Visible = True
    City.Visible = True
    lblShipPostalCode.Visible = True
    lblCountry.Visible = True
    ShipPostalCode.Visible = True
    ShipCountry.Visible = True

    ShipAddress.Text = CType(CType(FormView1.FindControl("Address"), TextBox).Text, String)
    ShipAddress.Visible = True

    I've also tried

    ShipAddress = CType(FormView1.FindControl("Address"), TextBox)
    ShipAddress.Visible = True


    I always end up with "Object reference not set to an instance of an object" error message

  • 1pcgeek

    Thanks Pat, I'm going to try that, I've been struggling with it also...

  • JJRUIZ

    No, sorry, I haven't used C in a long time

  • Javierm

    use the FormView FindControl method.
  • Steven Benjamin

    This question belongs in the Windows Forms forum.


  • zahnej

    Do you know how to do this in C#
  • Pass Values from Formview child controls to unbound textbox