帖子之后下拉不保留所选值回 [英] drop down not retaining selected value after post back

查看:142
本文介绍了帖子之后下拉不保留所选值回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是传统的ASP,我有一个下拉列表,用户选择,然后presses提交。他们preSS后提交下拉列表会恢复到默认值,而不是他们选择了什么。反正是有保持下降的状态下后背上,而不是将它返回到默认的?如果需要的话可以张贴code样品。
谢谢!

I'm using classic asp, I have a drop down list that the user selects and then presses submit. After they press submit the drop down list is going back to the default value instead of what they selected. Is there anyway to keep the state of the drop down between post backs instead of it going back to the default? Can post code sample if needed. Thanks!

推荐答案

您要中选择根据用户已发布的服务器端值

You have to "select it" serverside according to the values that the user has POSTed.

<select id="cars">
  <option value="volvo" 
      <%
      if request.form("cars") = "volvo" then 
          response.write("selected") 
      end if %>
      >Volvo</option>
  <option value="Saab" 
      <%
      if request.form("cars") = "Saab" then 
          response.write("selected") 
      end if %>
      >Saab</option>
  <option value="Mercedes" 
      <%
      if request.form("cars") = "Mercedes" then 
          response.write("selected") 
      end if %>
      >Mercedes</option>
  <option value="Audi" <%
      if request.form("cars") = "Audi" then 
          response.write("selected") 
      end if %>
      >Audi</option>
</select>

当然,你可能要自产自销自己的功能,避免所有的样板。

Of course, you might want to homegrown your own function to avoid all that boilerplate.

<% 
sub option(value, data, select_id) 
    Response.Write("<option value=""" & value & """)
    if request.form(select_id) = value then 
        Response.Write("selected") 
    end if
    Response.Write(">" & data & "</option>")
end sub
%>
' (...)
<select id="cars">
    <% option("volvo", "Volvo", "cars") %>
    <% option("Saab", "Saab", "cars") %>
    <% option("Mercedes", "Mercedes", "cars") %>
    <% option("Audi", "Audi", "cars") %>
</select>

如果您通过功能的空白 select_id ,也不会在意试图选择选择上回发。

If you pass the function a blank select_id, it will not care about trying to select the selected item of the select on postback.

这篇关于帖子之后下拉不保留所选值回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆