我有一个DropDownList
,我想检查浏览器有什么语言并相应地设置下拉列表中的值。
protected void Page_Load(object sender, EventArgs e)
{
string language = Request.UserLanguages[0].ToString().Substring(0, 2);
drpAnrede.DataSource = Server.MapPath("~/App_Data/" + language + ".xml");
}
更新:
我有这个问题的解决方案...
aspx:
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="drpAnrede" runat="server" DataTextField="display" DataValueField="id">
</asp:DropDownList>
<asp:XmlDataSource ID="xmldata" runat="server"></asp:XmlDataSource>
</div>
</form>
C#:
protected void Page_Load(object sender, EventArgs e)
{
string language = Request.UserLanguages[0].ToString().Substring(0, 2);
//drpAnrede.DataSource = Server.MapPath("~/App_Data/" + language + ".xml");
xmldata.DataFile = Server.MapPath("~/App_Data/" + language + ".xml");
drpAnrede.DataSourceID = xmldata.ID;
}