Use an array to populate a listbox?

前端 未结 4 1479
旧巷少年郎
旧巷少年郎 2021-01-16 11:00

The website I am working on will contain a drop-down list that shows a number of reason codes.

Is it possible to populate a drop-down list with an array derived from

4条回答
  •  走了就别回头了
    2021-01-16 11:19

    -- Edit:

    I've noticed you specifically wanted to bind to an array. I don't believe that is possible (may be wrong); I leave my example below of how to do it for a custom class, perhaps it is of use, perhaps not. Hopefully someone else answers you more directly.

    -- Old:

    Certainly it is, like so:

    ddlList.DataSource     = yourDataSource;
    ddlList.DataTextField  = "DisplayProperty";
    ddlList.DataValueField = "PropertyForValue";
    ddlList.DataBind();
    

    But note, in your example you've not posted the class, you've posted a method. In the example about 'yourDataSource' should be something like:

    List yourDataSource = new List();
    

提交回复
热议问题