我的 asp.net 页面上有 SQL 数据源,页面加载时出现此错误
“ddlTypes”有一个无效的 SelectedValue,因为它不存在于项目列表中。参数名称:值
private void GetQueryString(Uri tempUri)
{
if (HttpUtility.ParseQueryString(tempUri.Query).Get("IntrestFocus") != null)
{
ddlTopics.SelectedValue = HttpUtility.ParseQueryString(tempUri.Query).Get("IntrestFocus");
}
else
if (HttpUtility.ParseQueryString(tempUri.Query).Get("Skills") != null)
{
ddlSkills.SelectedValue = HttpUtility.ParseQueryString(tempUri.Query).Get("Skills");
}
else
if(HttpUtility.ParseQueryString(tempUri.Query).Get("Type") != null)
{
ddlTypes.SelectedValue = HttpUtility.ParseQueryString(tempUri.Query).Get("Type");
}
}
<asp:SqlDataSource ID="SqlDSTypes" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>" SelectCommand="SELECT * FROM [Types]"></asp:SqlDataSource>
<asp:DropDownList CssClass="selectpicker mobile-stack select-type" data-style="lts-white font-black drop-shadow select-height" ID="ddlTypes" runat="server" DataSourceID="SqlDSTypes" DataTextField="Description" DataValueField="Id" AppendDataBoundItems="True" ClientIDMode="Static">
<asp:ListItem Value="0">Select a Type</asp:ListItem>
</asp:DropDownList>