62,047
社区成员
发帖
与我相关
我的任务
分享
if (DropDownList_xxx.Items.FindByValue("数据库中查询到记录的值") != null)
{
DropDownList_xxx.SelectedValue = "xx";
}
this.DropDownList.Items.FindByValue(row["Name"].ToString()).Selected = true;
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="1">是</asp:ListItem>
<asp:ListItem Value="0">否</asp:ListItem>
</asp:DropDownList>
DropDownList1.SelectedValue = 数据库字段
DataTable dt = ck.backdatatalbeselect("select id,departname from department");
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "departname";
DropDownList1.DataValueField = "id";
DropDownList1.SelectedValue = 你查询出来的值(应该跟Id对应的值);
DropDownList1.DataBind();
既然你都查出来了,就没有必要再去循环比对。。直接复制就ok了