C#:
protected void Page_Load(object sender, EventArgs e)
{
//由於DropDownList只能單選,為了避免錯誤,先將已選定的項目取消
this.DropDownList1.Items[DropDownList1.SelectedIndex].Selected = false;
//尋找符合"1"的項目
ListItem item=this.DropDownList1.Items.FindByValue("1");
//如果在DropDownList清單中有找到相符的,則將它改成被選取的項目
if(item!=null)item.Selected = true;
}
沒有留言:
張貼留言