ASP If then else questions

Discussion in 'C#' started by mwright, Sep 19, 2006.

  1. #1
    Hello,



    I am trying to use response.write in a if statement, and I want it to output to a specific column in my table.. when I place the if statment in the section I want it and run it I get a syntax error..
    Can you please help

    my code is a follows for the if statement. I am pulling a result from the SQL server if it matches I have my first response if it does not I have my second response. it sounded simple to me but I am having a boohoo of a time.. Thanks for your help


    <% if (answerRS.Fields.Item("q1").Value) = "1" then
    Response.write = "Correct"
    Else Response.Write = "Incorrect"
    End If%>

    If you think I should outout to a text box and not a section in the table please let me know and if possible sample code would be helpful I am a newbie
     
    mwright, Sep 19, 2006 IP
  2. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #2
    try this
    you can't write the response.write after IF or ELSE
     
    ludwig, Sep 19, 2006 IP
  3. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try

    <%
    if (answerRS("q1")) = "1" then
    Response.write ("Correct")
    Else
    Response.Write("Incorrect")
    End If
    %>

    first line is just neater syntax, real error I thin was the "response.write =" . If that doesn't work post the syntax error

    regards
     
    Free Born John, Sep 19, 2006 IP
  4. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #4
    yes sorry, didn't see the =
     
    ludwig, Sep 19, 2006 IP
  5. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #5
    <%

    if not answerRS.eof then
    if (answerRS("q1")) = "1" then
    Response.write ("Correct")
    Else
    Response.Write("Incorrect")
    End If
    end if
    %>
     
    shaileshk, Sep 20, 2006 IP