Results 1 to 2 of 2

Thread: Textbox action in datalist [Resolved]

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Location
    Ottawa
    Posts
    38

    Textbox action in datalist [Resolved]

    I hope this is as simple as I think it is, but for some reason, I cannot see the forest through the trees. On my page I have a datalist that, during edit mode, displays several text boxes for the user to type in. What I want to is poll a database after the user types in a value into say 'TextBox1'. I just cannot figure out the correct path to the TextBox events when it's a part of the DataList Edit section. Any ideas ? Thanks.
    Last edited by cfisher; Mar 11th, 2005 at 09:35 AM. Reason: Problem Resolved

  2. #2

    Thread Starter
    Member
    Join Date
    Aug 2001
    Location
    Ottawa
    Posts
    38

    Re: Textbox action in datalist [Resolved]

    It took some digging, but I finally figured out the code to access a textbox within a datalist (thanks to all who helped). I have added the code below and attempted to explain what's going on, but I may not have the wording exactly correct.

    Code:
    Dim i As Integer
    Dim crt As Control
    
    ‘Find the datalist control on the page
       For i = 0 To Me.DataList.Controls.Count – 1
       ‘Once the datalist is found, find the textbox control within the datalist
                For Each crt In Me.DataList.Controls(i).Controls
                    ‘Establish a connection to the datalist control line
                    Dim item As DataListItem = Me.DataList.Controls(i)
                    ‘Find the text box within the row
                    Dim tbx As System.Web.UI.WebControls.TextBox =item.FindControl("TextBox1")
                    If (crt.ID = "TextBox1") Then
                        If tbx.Text = "Hi" Then
                            tbx.Text = "Hi There"
                        Else
                            tbx.Text = "Bye then"
                        End If
                    End If
                Next
       Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width