당신은 뒤에 DropDownList로
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Netherlands" Value="nl-NL"></asp:ListItem>
<asp:ListItem Text="England" Value="en-GB"></asp:ListItem>
<asp:ListItem Text="Germany" Value="de-DE"></asp:ListItem>
</asp:DropDownList>
코드의 값을 저장하기 위해 세션을 사용할 수 있습니다, 모든 페이지로드에있는 드롭 다운의 올바른 값을 설정합니다. 이제 Session["language"]
값을 사용하여 데이터를 필터링 할 수 있습니다.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//check if the session exists and select the correct value in the dropdownlist
if (Session["language"] != null)
{
DropDownList1.SelectedValue = Session["language"].ToString();
}
else
{
//set the session with the default language
Session["language"] = "en-GB";
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//set the session based on the dropdownlist value
Session["language"] = DropDownList1.SelectedValue;
}