c#dropdownlist是否避免多个insert语句?

c#dropdownlist是否避免多个insert语句?,c#,asp.net,webforms,C#,Asp.net,Webforms,这是c代码: 有没有办法避免顺序插入dropdownlist和批量插入这些值?试试这个 ddl.Items.Add(new ListItem("--Select Me--", "0")); ddl.Items.Add(new ListItem("I'm the first", "1")); ddl.Items.Add(new ListItem("I'm the second", "2")); ddl.Items.Add(new ListItem("I'm the third", "3"));

这是c代码:

有没有办法避免顺序插入dropdownlist和批量插入这些值?

试试这个

ddl.Items.Add(new ListItem("--Select Me--", "0"));
ddl.Items.Add(new ListItem("I'm the first", "1"));
ddl.Items.Add(new ListItem("I'm the second", "2"));
ddl.Items.Add(new ListItem("I'm the third", "3"));
试试这个

ddl.Items.Add(new ListItem("--Select Me--", "0"));
ddl.Items.Add(new ListItem("I'm the first", "1"));
ddl.Items.Add(new ListItem("I'm the second", "2"));
ddl.Items.Add(new ListItem("I'm the third", "3"));
您可以这样做:

DropDownList ddl;
var ls=new List<KeyValuePair<int,string>>()
{
    new KeyValuePair<int,string>(0,"--Select Me--"),
    new KeyValuePair<int,string>(1,"I'm the first"),
    new KeyValuePair<int,string>(2,"I'm the second"),
    new KeyValuePair<int,string>(3,"I'm the third"),
};
ddl.DataTextField="Value";
ddl.DataValueField="Key";
ddl.DataSource=ls;
ddl.DataBind();
dropdownlistddl;
var ls=新列表()
{
新的KeyValuePair(0,“--选择我--”,
新的KeyValuePair(1,“我是第一”),
新的KeyValuePair(2,“我是第二个”),
新的KeyValuePair(3,“我是第三个”),
};
ddl.DataTextField=“Value”;
ddl.DataValueField=“Key”;
ddl.DataSource=ls;
ddl.DataBind();
您可以执行以下操作:

DropDownList ddl;
var ls=new List<KeyValuePair<int,string>>()
{
    new KeyValuePair<int,string>(0,"--Select Me--"),
    new KeyValuePair<int,string>(1,"I'm the first"),
    new KeyValuePair<int,string>(2,"I'm the second"),
    new KeyValuePair<int,string>(3,"I'm the third"),
};
ddl.DataTextField="Value";
ddl.DataValueField="Key";
ddl.DataSource=ls;
ddl.DataBind();
dropdownlistddl;
var ls=新列表()
{
新的KeyValuePair(0,“--选择我--”,
新的KeyValuePair(1,“我是第一”),
新的KeyValuePair(2,“我是第二个”),
新的KeyValuePair(3,“我是第三个”),
};
ddl.DataTextField=“Value”;
ddl.DataValueField=“Key”;
ddl.DataSource=ls;
ddl.DataBind();
使用以下方法:

使用以下方法:

这可能会有帮助:

List<ListItem> items = new List<ListItem>();
  items.Add(new ListItem("Alabama", "Alabama"));
  items.Add(new ListItem("Alaska", "Alaska"));
  DropDownList1.Items.AddRange(items.ToArray());
List items=newlist();
添加(新列表项目(“阿拉巴马州”、“阿拉巴马州”);
添加(新列表项(“阿拉斯加”、“阿拉斯加”));
DropDownList1.Items.AddRange(Items.ToArray());
这可能会有帮助:

List<ListItem> items = new List<ListItem>();
  items.Add(new ListItem("Alabama", "Alabama"));
  items.Add(new ListItem("Alaska", "Alaska"));
  DropDownList1.Items.AddRange(items.ToArray());
List items=newlist();
添加(新列表项目(“阿拉巴马州”、“阿拉巴马州”);
添加(新列表项(“阿拉斯加”、“阿拉斯加”));
DropDownList1.Items.AddRange(Items.ToArray());