下拉列表问题

时间:2010-06-23 06:56:20

标签: drop-down-menu

我尝试在drodownlist中添加一个新项目。我希望添加的项目放在下拉列表的第一个位置。我该怎么做

   I want this to be a first option
   ListItem itemspecial = new ListItem();
   itemspecial.Value = "-1";
   itemspecial.Text = "Please select specialization";
   ddlSpecialization.Items.Add(itemspecial);

    ddlSpecialization.DataTextField = "Description";
    ddlSpecialization.DataValueField = "Id";
    ddlSpecialization.DataSource = objspecial.GetAll();
    ddlSpecialization.DataBind();

3 个答案:

答案 0 :(得分:0)

您可以使用Insert

DropDownList功能执行此操作
ListItem itemspecial = new ListItem();
itemspecial.Value = "-1";
itemspecial.Text = "Please select specialization";
ddlSpecialization.Items.Insert(0, itemspecial);

ddlSpecialization.DataTextField = "Description";
ddlSpecialization.DataValueField = "Id";
ddlSpecialization.DataSource = objspecial.GetAll();
ddlSpecialization.DataBind();

答案 1 :(得分:0)

Databind在您插入之前首先...

ddlSpecialization.DataTextField = "Description";
ddlSpecialization.DataValueField = "Id";
ddlSpecialization.DataSource = objspecial.GetAll();
ddlSpecialization.DataBind();

ddlSpecialization.Items.Insert(0, new ListItem("Please select specialization", "-1"));

答案 2 :(得分:-1)

使用 - ddlSpecialization.Items.insertAt(itemspecial,0);< -Specify第一个索引,