我有一个下拉列表如下图所示:下拉列表刷新页面时保持选定值不变
<asp:DropDownList ID="DropDownList1" cssclass="ddStyle" runat="server" DataSourceID="SqlDataSource2" DataTextField="company" DataValueField="SECid" Width="100%" AppendDataBoundItems="true" AutoPostBack="True" EnableViewState="true" ViewStateMode="Enabled">
<asp:ListItem Text="--Select One--" Value="" />
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1"></asp:RequiredFieldValidator>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="select distinct secid, company from .... order by company"></asp:SqlDataSource>
VB的背后是
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Selection As String = Nothing
If Not DropDownList.SelectedValue Is Nothing Then Selection = DropDownList.SelectedValue
Session("Selected") = Selection
End Sub
我要实现的是,当我刷新页面后,我对dropdwonlist做出选择时,下拉列表将不会返回到“ - select one--”,而是保留其最后选定的项目。我想知道它有什么解决方案?
感谢您的咨询!
你能告诉我你的代码 - 背后?你在Page_Load中有什么? –
嗨,后面的VB代码是一个按钮点击(如上所述)。我目前没有任何page_load子。 – user3344443
等一下,也许我想不明白:你不想让DropDownList在任何refreash后改变选定的项目?所以当页面刷新时,你希望DropDownList保留其最后选择的项目? –