Results 1 to 5 of 5

Thread: For loop with if else statement<resolved>

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    38

    Question For loop with if else statement<resolved>

    i wan the page to jump to another page if the statement is not true...

    Dim i As Integer
    For i = 0 To ds.Tables(0).Rows.Count - 1
    If id = ds.Tables(0).Rows(i)(0) Then
    name.Text = ds.Tables(0).Rows(i)(1)
    gender.Text = ds.Tables(0).Rows(i)(1)
    dob.Text = ds.Tables(0).Rows(i)(1)
    mail.Text = ds.Tables(0).Rows(i)(1)
    label2.Text = ds.Tables(0).Rows(i)(1)

    ELSE

    End If

    Next

    where should i put my respon.redirect?
    if i put after the else it will go straight to the page after one loop...
    how?
    can any help???
    Last edited by nikverse; Apr 7th, 2003 at 01:39 PM.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Not sure exactly what you mean, but try something like this:

    Code:
    Dim i As Integer 
    Dim redirect As Boolean = False
    
    For i = 0 To ds.Tables(0).Rows.Count - 1 
    If id = ds.Tables(0).Rows(i)(0) Then 
    name.Text = ds.Tables(0).Rows(i)(1) 
    gender.Text = ds.Tables(0).Rows(i)(1) 
    dob.Text = ds.Tables(0).Rows(i)(1) 
    mail.Text = ds.Tables(0).Rows(i)(1) 
    label2.Text = ds.Tables(0).Rows(i)(1) 
    ELSE 
    redirect = True
    End If 
    Next 
    
    If redirect = True Then
    Response.Redirect("mypage")
    End If

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    38
    but this way it will onli do the FOR loop once... ???
    isin't it?

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    No, it will do the for loop all the way through. After it is done, it will see if the for loop changed the boolean to true. If it did, then it will redirect.

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    38
    ok
    thanks..
    got the idea liao...
    really thanks

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