C# DropDownList with a Dictionary as DataSource

前端 未结 4 1396
醉梦人生
醉梦人生 2020-12-12 20:13

I want to set DataTextField and DataValueField of a Dropdownlist (languageList) using a Dictionary (list) of languageCod

4条回答
  •  心在旅途
    2020-12-12 20:45

    If the DropDownList is declared in your aspx page and not in the codebehind, you can do it like this.

    .aspx:

    
    

    .aspx.cs:

    protected void Page_Load(object sender, EventArgs e)
    {
        ddlStatus.DataBind();
        // or use Page.DataBind() to bind everything
    }
    
    public Dictionary Statuses
    {
        get 
        {
            // do database/webservice lookup here to populate Dictionary
        }
    };
    

提交回复
热议问题