首先在添加引用using System.Text.RegularExpressions;
(!IsPostBack)声明一个函数
if (!IsPostBack)
{
DropDownList1_Binding();
{
在最后面添加以下代码
private void DropDownList1_Binding()
{
this.DropDownList1.DataSource = GetData().Select(yn => new { value = yn }).ToList();
this.DropDownList1.DataTextField = "value";
this.DropDownList1.DataBind();
}
private List<string> GetData()
{
List<string> yn = new List<string>();
yn.Add("xxx");
yn.Add("xxx");
return yn;
}