现在的位置: 首页 > 综合 > 正文

ASP.NET 设置DropDownList选中项

2018年09月24日 ⁄ 综合 ⁄ 共 419字 ⁄ 字号 评论关闭
//给DropDownList1添加项

    ……
    ……
    //如果DropDownList1的Text和Value值一致
    this.DropDownList1.SelectedIndex
= this.DropDownList1.Items.IndexOf(new ListItem(指定项));
    //如果Text和Value值不一致
    //指定Text值
    this.DropDownList1.SelectedIndex
= this.DropDownList1.Items.IndexOf(this.DropDownList1.Items.FindByText(指定项));
    //指定Value值
    this.DropDownList1.SelectedIndex = this.DropDownList1.Items.IndexOf(this.DropDownList1.Items.FindByValue(指定项));

抱歉!评论已关闭.