DropDownList1 预设了三个值<asp:DropDownList CssClass="STYLE4" ID="DropDownList1" runat="server" Width="138">
<asp:ListItem Value="MORNING">上午</asp:ListItem>
<asp:ListItem Value="MIDDLE">中午</asp:ListItem>
<asp:ListItem Value="NIGHT">晚上</asp:ListItem>
</asp:DropDownList>不绑定时 默认显示的是 “上午”不如现在有一个button 事件触发后,想实现绑定数据库中(数据库中的值也只有“上午,中午,晚上”)的值 “中午”
DropDownList1 的预设值变为“中午”
<asp:ListItem Value="MORNING">上午</asp:ListItem>
<asp:ListItem Value="MIDDLE">中午</asp:ListItem>
<asp:ListItem Value="NIGHT">晚上</asp:ListItem>
</asp:DropDownList>不绑定时 默认显示的是 “上午”不如现在有一个button 事件触发后,想实现绑定数据库中(数据库中的值也只有“上午,中午,晚上”)的值 “中午”
DropDownList1 的预设值变为“中午”
item.Selected=true;
DropDownList.Items.FindByText(数据库去出来的值).Selected=true;
给的值一定是下拉框里面有的,不能会出错
if(!ispostback)
{
dropdownlist.selectvalue="上午";
}按钮事件里面
dropdownlist.selectvalue="中午";
dropdownlist.ClearSelection();
这句话很关键,否则可能会报错
其作用是为了使dropdownlist一项也不选中
然后再DropDownList.Items.FindByText(数据库去出来的值).Selected=true;
if (this.DropDownList1.Items.FindByValue("取出值") != null)
this.DropDownList1.SelectedValue = 取出值;