how t orestore values back to drop down list afterpost back

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gotonagle
    New Member
    • Nov 2007
    • 19

    how t orestore values back to drop down list afterpost back

    hi , i m new to asp and leraning it...
    i have only one page in which i take some values like name, dob and education degree. after post back i return to this page iteslf.. but the values in dropdown list is not tha what i hadve selected(coz it do not support viewstates).
    is there any method to retrive the values back in drop down.
    for text i m usoing like this.
    <tr>
    <td align="right" > Name : </td>
    <td><input type=text id=txtName name=Name style="width: 300px" value="<%=reque st.Form("Name") %>" /></td>
    </tr>

    and for drop down i m using like this.......
    <tr>
    <td align="right"> Qualification : </td>
    <td><select style="width: 300px" id= ddlDegree name=degree>
    <option value="1" <%=BE %> >BE</option>
    <option value="2" <%=BTECH %>>B TECH</option>
    <option value="3" <%=MCA %>>MCA</option>
    <option value="4" <%=MBA %>>MBA</option>
    <option value="5" <%=MTECH %>>M TECH</option>
    </select></td>
    </tr>

    <%
    select case (request.Form(" degree"))

    case "1"
    BE="selected"
    case "2"
    BTECH="selected "
    case "3"
    MCA="selected"
    case "4"
    MBA="selected"
    case "5"
    MTECH="selected "

    end select
    %>


    but what if i have too many values in drop down.. is ther any better way to do this???
    pls help..
    thnx in advance.
  • stepterr
    New Member
    • Nov 2007
    • 157

    #2
    Originally posted by gotonagle
    hi , i m new to asp and leraning it...
    i have only one page in which i take some values like name, dob and education degree. after post back i return to this page iteslf.. but the values in dropdown list is not tha what i hadve selected(coz it do not support viewstates).
    is there any method to retrive the values back in drop down.
    for text i m usoing like this.
    <tr>
    <td align="right" > Name : </td>
    <td><input type=text id=txtName name=Name style="width: 300px" value="<%=reque st.Form("Name") %>" /></td>
    </tr>

    and for drop down i m using like this.......
    <tr>
    <td align="right"> Qualification : </td>
    <td><select style="width: 300px" id= ddlDegree name=degree>
    <option value="1" <%=BE %> >BE</option>
    <option value="2" <%=BTECH %>>B TECH</option>
    <option value="3" <%=MCA %>>MCA</option>
    <option value="4" <%=MBA %>>MBA</option>
    <option value="5" <%=MTECH %>>M TECH</option>
    </select></td>
    </tr>

    <%
    select case (request.Form(" degree"))

    case "1"
    BE="selected"
    case "2"
    BTECH="selected "
    case "3"
    MCA="selected"
    case "4"
    MBA="selected"
    case "5"
    MTECH="selected "

    end select
    %>


    but what if i have too many values in drop down.. is ther any better way to do this???
    pls help..
    thnx in advance.



    Typically what I do is include an if statement within my options. Such as:

    <option value="1" <%if (request.Form(" degree")=1)then %>selected<%en d if%>>BE</option>

    Comment

    • gotonagle
      New Member
      • Nov 2007
      • 19

      #3
      yaa i got it
      thnx for help

      Comment

      • gotonagle
        New Member
        • Nov 2007
        • 19

        #4
        thnx agian for ur help and i hpope you will chck it again

        i have one concern in ths that
        would it not create more complexity coz for first time i was checking for value only once and here i have to checjk for every item in select box..
        my question was if i have less no of items in my dropdown than my code was ok but what if i have large no of items in that...

        pls let me know if m concern is wrong or any better thing we can do....
        thnx again :)

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          Are you generating the dropdown list from an array or a db? if so, you can do something like this:
          Code:
          do until rs.eof %>
             <option value="<%=rs("myFieldName")%>"
             <% if request("thisInputName") = rs("myFieldName") then response.write "selected"%>
             ><%=rs("myFieldName")%></option>
             <%
             rs.movenext
          loop
          Let me know if this helps.

          Jared

          Comment

          Working...