Solved

place textbox text into another textbox when button clicked in repeater

Posted on 2006-11-02
4
348 Views
Last Modified: 2008-02-01
I am populating textbox2 with data from the database what i would like to try and do is populate textbox1 with text from textbox2 when button1 is clicked.  This is what i have so far. I am not exactly sure the vb code should be. So the question is what should the vb code be?


<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource2">
       <ItemTemplate>
               <%-- <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /><br />--%>
               <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
               <asp:TextBox ID="TextBox2" runat="server" text='<%# Eval("ShipCity") %>'></asp:TextBox><br />
               <asp:Button ID="Button1" runat="server" Text="edit" OnClick="Update" />
        </ItemTemplate>
</asp:Repeater>

0
Comment
Question by:samme
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Sammy earned 250 total points
ID: 17864324
Try this

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource2" OnItemCommand="repeater1_ItemCommand">
       <ItemTemplate>
               <%-- <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /><br />--%>
               <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
               <asp:TextBox ID="TextBox2" runat="server" text='<%# Eval("ShipCity") %>'></asp:TextBox><br />
               <asp:Button ID="Button1" runat="server" Text="edit" OnClick="Update" CommandName="Update" />
        </ItemTemplate>
</asp:Repeater>
Private Sub repeater1_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs)
        If (e.CommandName = "Updade") Then
            Dim TextFromTextBox2 As String = CType(e.Item.FindControl("TextBox2"),TextBox).Text
           Dim txtTemp as new TextBox= Ctype(e.Item.FindControl("TextBox1"),TextBox)
                  txtTemp.Text=TextFromTextBox2
        End If
    End Sub

Here we use the ItemCommand event of the data repeater and the CommandName property of the button to get the text
0
 
LVL 1

Author Comment

by:samme
ID: 17866407
2 errors show up

Ctype(e.Item.FindControl("TextBox1"),TextBox) <---end of statement expected error
txtTemp.Text<---txtTemp not declared error
0
 
LVL 1

Author Comment

by:samme
ID: 17866523
Corrected like this: I had to take the new out

Protected Sub Repeater1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles Repeater1.ItemCommand
        If (e.CommandName = "Update") Then
            Dim TextFromTextBox2 As String = CType(e.Item.FindControl("textbox2"), TextBox).Text
            Dim txtTemp As TextBox = CType(e.Item.FindControl("textbox1"), TextBox)
            txtTemp.Text = TextFromTextBox2
        End If

    End Sub
0
 
LVL 27

Expert Comment

by:Sammy
ID: 17868755
Sorry Samme,
I was too tired to see anything when I answered your question.
Glad you got it fixed

Good luck

Sammy
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now