在Default.aspx中,我有一个下拉列表,用于从“对象数据”源中提取索引类型。下面的代码
<h4>Index to search</h4>
<asp:DropDownList ID="dlSearchIndex" runat="server" CssClass="input-group "
DataTextField="INDEX" DataValueField="INDEX" Width="150px"
DataSourceID="ObjectDataSource1">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetIndexType" TypeName="the.dll">
</asp:ObjectDataSource>
我正在尝试使用cookie来设置此下拉列表的selectedvalue,如下所示:
If IsPostBack = False Then
If Request.Cookies("IndexToSearch") IsNot Nothing Then
dlSearchIndex.SelectedValue =
Request.Cookies("IndexToSearch").Value.ToString()
Response.Cookies("IndexToSearch").Value =
dlSearchIndex.SelectedValue
Response.Cookies("IndexToSearch").Expires =
DateTime.Now.AddSeconds(10)
Else
Response.Write("<p> No Cookie Found.</p>")
End If
End If
我正在这样创建cookie:
If Request.Cookies("IndexToSearch") Is Nothing Then
Dim cookie As New HttpCookie("IndexToSearch")
cookie.Value = Trim(dlSearchIndex.SelectedValue)
cookie.Expires = DateTime.Now.AddSeconds(350)
Response.SetCookie(cookie)
Response.Write("<p>" & cookie.Name & ":" & cookie.Value & ":")
End If
我第一次运行此代码时,它可以工作,但此后出现此错误:
"dlSearchIndex" has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value
请,我在做什么错?预先谢谢你!