convert object/type

Results 1 to 2 of 2

Thread: convert object/type

  1. #1
    Join Date
    Dec 1969

    Default convert object/type

    I have a unspecified number of text boxes that are built as the page loads. which works fine, but then I have a function that needs to read them. Since there is a different amount of boxes each time, I need to figure out how to retrive the values in the text boxes.<BR><BR>Here is what i started with but I am not sure how to get the values, this is not working:<BR><BR> Private Sub btnGetItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetItems.Click<BR> Dim x, n As Integer<BR> Dim obj As Object<BR> n = Session("qi")<BR><BR> Do Until n = 0<BR> obj = Page.FindControl("txt" & n)<BR> Dim txtbox As TextBox()<BR> txtbox = obj<BR> x = txtbox.text<BR> Loop<BR><BR> txtCItems.Text = x<BR> End Sub

  2. #2
    Join Date
    Dec 1969

    Default Well, code makes no sense...

    n = Session("qi")<BR><BR>Do Until n = 0<BR> ...<BR>Loop<BR><BR>But NOTHING *inside* the DO loop changes the value of n.<BR><BR>So either the loop will execute forever (if n starts out as non-zero) or will not execute at all (if n starts out as zero).<BR><BR>And if there is no value in the session variable, then I&#039;d expect a conversion error.<BR><BR>And why do you declare txtbox as an array?? You certainly don&#039;t then assign an array to it, so no wonder it goes kablooey.<BR><BR>And, finally, no matter what happens you will be only grabbing the *last* text box in your loop.<BR><BR>I might do something like this (just GUESSING as to what you intended):<BR><BR>Private Sub btnGetItems_Click(ByVal s As Object, ByVal e As EventArgs) Handles btnGetItems.Click<BR> Dim n As Integer<BR> Dim all As String<BR> Dim obj As Object<BR><BR> all = ""<BR> For n = 0 To 9999999 &#039; or 1 To, depending on how you numbered things<BR> obj = Page.FindControl("txt" & n)<BR> If IsNothing( obj ) Then Exit For &#039; quit after last valid "txtN"<BR> s &= ( " " & CTYPE( obj, Textbox ).Text )<BR> Next<BR> txtCItems.Text = s<BR>End Sub<BR><BR>

Posting Permissions

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