我一直在努力使它工作几个小时。我认为问题出在使用枚举,但是老板坚持要使用枚举。
webapp的aspx代码:
<label for="footerPlaceHolder_twoFactorAuthentication" class="sr-only"><asp:Localize runat="server" Text="<%$ Resources:UserMessages, TwoFactorSelect %>"></asp:Localize></label>
<asp:DropDownList runat="server" ID="twoFactorAuthenticationDropDownList" CssClass="selectpicker">
<asp:ListItem Value="0" Text = "<%$ Resources:UserMessages, TwoFactorSelect %>"></asp:ListItem>
<asp:ListItem Value="3" Text = "<%$ Resources:UserMessages, TwoFactorRequire %>" ></asp:ListItem>
<asp:ListItem Value="2" Text = "<%$ Resources:UserMessages, TwoFactorRecommend %>" ></asp:ListItem>
<asp:ListItem Value="1" Text = "<%$ Resources:UserMessages, TwoFactorNotRequired %>" ></asp:ListItem>
</asp:DropDownList>
<p><asp:RequiredFieldValidator runat="server" ControlToValidate="twoFactorAuthenticationDropDownList" CssClass="field-validation-error" InitialValue="0" EnableClientScript="true" Display="Dynamic"></asp:RequiredFieldValidator></p>
webapp aspx.cs代码:
var data = Utility.OAWebServiceClient.GetFullSiteData(rowToEdit);
twoFactorAuthenticationDropDownList.SelectedValue = data.TwoFactorOption.ToString();
网络服务IOAuth2.cs代码:
public enum WebSite2FactorOptionEnum
{
[EnumMember]
NotSelected,
[EnumMember]
NotRequired,
[EnumMember]
Recommended,
[EnumMember]
Required
}
问题是下拉菜单中的值为int
s,但您将其设置SelectedValue
为string。
尝试:
twoFactorAuthenticationDropDownList.SelectedValue = ((int)data.TwoFactorOption).ToString();
希望它会有所帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句