0

I have a DropDownList and I want to check what language does the browser have and set the values in the dropdown accordingly.

 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");
 }

UPDATE:

I have the solution for this problem...

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;
        }
Tarasov
  • 3,625
  • 19
  • 68
  • 128

2 Answers2

1

Assuming the XML is Ok, you need to call

drpAnrede.DataBind();

after applying the datasource.

webnoob
  • 15,747
  • 13
  • 83
  • 165
1

You have to call DataBind() on your dropdown list after you set the datasource, no?

As in:

Databinding DropDown Control in .Net

Community
  • 1
  • 1
Mr. Mr.
  • 4,257
  • 3
  • 27
  • 42