Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

place textbox text into another textbox when button clicked in repeater

Posted on 2006-11-02
4
Medium Priority
?
403 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 Ageil earned 1000 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 Ageil
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

804 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