Solved

place textbox text into another textbox when button clicked in repeater

Posted on 2006-11-02
4
363 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

23 Experts available now in Live!

Get 1:1 Help Now