(asp.net c#)DropDownList绑定后显示对应的项的两种方法 |
本文标签:DropDownList,绑定 方法一: 实现代码 复制代码 代码如下: DropDownList1.DataSource = listSort; DropDownList1.DataTextField = "LogSortName"; DropDownList1.DataValueField = "LogSortID"; DropDownList1.DataBind(); DropDownList1.SelectedIndex = ddl.Items.IndexOf(DropDownList1.Items.FindByValue("i")); //i要自己去获取你要显示的项的id 。 方法二:我贴上部分代码 获取数据后 根据该value去配对你想要的项 。 不过图中的for改成 do…while 应该会更省事一点 。 |