【问题标题】:How I can fill the DropDownList in the page_load如何在 page_load 中填写 DropDownList
【发布时间】:2013-02-12 22:48:19
【问题描述】:

我有一个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;
        }

【问题讨论】:

  • 里面没有问题。
  • 他的问题是这个问题的标题。

标签: c# asp.net xml browser html-select


【解决方案1】:

设置数据源后,您必须在下拉列表中调用DataBind(),不是吗?

如:

Databinding DropDown Control in .Net

【讨论】:

    【解决方案2】:

    假设XML没问题,你需要调用

    drpAnrede.DataBind();
    

    应用数据源之后。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-30
      相关资源
      最近更新 更多