在数据更新页里怎样才能使DropDownList根据原来数据自动选中一项

it2022-05-09  26

 

答1: c# 的代码看不太懂,不过最简单的做法是 手动在 第一项添加 select 行 ______________________________________________________________________________________________ 答2: DropDownList1.Items[index].Selected = true;

就可以了 ______________________________________________________________________________________________ 答3: FindByValue方法返回其值为指定字符串的ListItem,而不是选中它,所以你的代码中 DropDownList1.Items.FindByValue(type); 没有任何作用,你可以改为这样:

ListItem lItem=DropDownList1.Items.FindByValue(type); if(lItem!=null) lItem.Selected=true; ______________________________________________________________________________________________ 答4: DropDownList1.DataBind(); string type=dr["Texttype_id"].ToString();

DropDownList1.SelectedIndex=   this.DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(type));

______________________________________________________________________________________________ 答5: DropDownList1.SelectedIndex=   this.DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(你要找的值));

DropDownList1.SelectedIndex=   this.DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(显示的文本));

 

转载于:https://www.cnblogs.com/nanshouyong326/archive/2008/12/13/1354229.html


最新回复(0)