0

我的标记页面如下:

<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Description" DataValueField="Value" />
<asp:DropDownList ID="DropDownList2" runat="server" DataTextField="Description" DataValueField="Value" />

我的代码是:

class grade
{
    public string Description { get; set; }
    public string Value { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
    List<grade> gradeList = new List<grade>()
      { new grade {Description="Poor", Value="1"}, 
          new grade { Description="Average", Value="2"}, 
          new grade {Description="Good", Value="4" } };
    //in real life the above list is read from a database

    DropDownList1.DataSource = gradeList;   DropDownList1.DataBind();
    DropDownList2.DataSource = gradeList;   DropDownList2.DataBind();
}

以上对我来说很好。我能够在运行时为两个 DropDownLists 更改 SelectedValue 和 SelectedIndex 而不会出错。我可以知道以上是否是犹太洁食。

谢谢。

4

1 回答 1

1

是的,像这样使用它非常好。但是您可以使用Dictionary<string,string>而不是 Grade 类。

于 2013-06-03T03:08:06.130 回答