我在 ASP.net 中添加了 DropDownList。
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
<asp:ListItem Text="Name" Value="jsh" Selected="true" />
<asp:ListItem Text="hhh" Value="sds"/>
</asp:DropDownList>
而不是Selected="true"
在 ASP.net 中说我想在
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList1 // THE SELECTED ITEM NEEDS TO BE SET TO TRUE
Response.Redirect(Request.RawUrl);
}
更新
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" OnTextChanged="DropDownList1_onChanged">
</asp:DropDownList>
C#
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
DropDownList1.Items.Add(new ListItem("En", "en-US"));
DropDownList1.Items.Add(new ListItem("Fr", "fr-FR"));
}
}
// 我也复制了InitializeCulture()
protected override void InitializeCulture()
{
string Kultur = "en-US";
if (Session["lang"] != null)
{
Kultur = Session["lang"].ToString();
}
this.UICulture = Kultur;
this.Culture = Kultur;
base.InitializeCulture();
}
//
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList1.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;
Response.Redirect(Request.RawUrl);
}